|
Hi Lloyd, thanks for the comment
The problem was resolved drawing directly the lines of the barcode in a Canvas
Since WPF thinks, draws (and also prints) vectorial it hasn't any problem handling vectorial shapes (at this point the real limit is only given by the printer's physical resolution), viceversa it could have problems handling raster images because it's not the way it's used to think and, like you said before it plainly translates bitmap pixels to WPF units without any sort of scale, so at 96DPIs (unless you set a different DPI value from Control Panel --> Display Settings but that's a different story and not a viable option in my case because printers are not monitors and will always have different resolutions).
modified 20-Nov-12 5:07am.
|
|
|
|
|
I have issues with the C# WPF WebBrowser class
I have a C# WPF application which uses a WebBrowser class. I have overwritten the LoadComplete method. The question I have is this. This method is supposed to be triggered when the class has completed a load, but , when I put a breakpoint on this method, it is called before the class visually has compleded a load. Because of this, the htmldata is not complete. Any ideas?
Maybe there is a different method I should overide. LoadComplete might not be the best choice. Maybe there is something that is the same as a "display complete".
|
|
|
|
|
What do you mean when you say that "the htmldata is not complete"? You can access the mshtml.HTMLDocument object from the .Document property of the WebBrowser object in the LoadComplete event.
As for the "visuals", the page is rendered on the main UI thread. Since LoadComplete runs on the main UI thread (when the page has been loaded, but not yet displayed), the page will not display until LoadComplete exits ... unless you tell the thread's Dispatcher to process pending UI events (see DispatcherFrame in VS / C# Help).
|
|
|
|
|
It seems no amount of SnapsToDevicePixels="True" and/or UseLayoutRounding="True" can make the border around a Paragraph sharp:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FlowDocumentReader>
<FlowDocument>
<Paragraph BorderBrush="Black" BorderThickness="1" Padding="10">
<InlineUIContainer>
<Expander Header="An expander" >
<Button>A button</Button>
</Expander>
</InlineUIContainer>
</Paragraph>
<Paragraph BorderBrush="Black" BorderThickness="1" Padding="10">
<InlineUIContainer>
<Expander Header="An expander" >
<Button>A button</Button>
</Expander>
</InlineUIContainer>
</Paragraph>
<Paragraph BorderBrush="Black" BorderThickness="1" Padding="10">
<InlineUIContainer>
<Expander Header="An expander" >
<Button>A button</Button>
</Expander>
</InlineUIContainer>
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
</Window>
However i can use RenderOptions.EdgeMode="Aliased" which makes the border sharp, but distorts the Expander:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FlowDocumentReader RenderOptions.EdgeMode="Aliased">
<FlowDocument>
<Paragraph BorderBrush="Black" BorderThickness="1" Padding="10">
<InlineUIContainer>
<Expander Header="An expander" >
<Button>A button</Button>
</Expander>
</InlineUIContainer>
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
</Window>
So, is there any way to make the border sharp without hurting the documents appearance?
|
|
|
|
|
If you placed the Expanders (with a border) "outside" the FlowDocument (in a FrameworkElement), you could use UseLayoutRounding to get the effect you want.
As presented, I don't see why these expanders have to be inside a FlowDocument (which isn't a FrameworkElement).
|
|
|
|
|
Ok i figured out a way that works, although its a bit ugly:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<FlowDocumentScrollViewer>
<FlowDocument>
<Paragraph>
<InlineUIContainer>
<Border BorderBrush="Black" BorderThickness="1" Padding="10" SnapsToDevicePixels="True">
<Expander>
<Expander.Header>
<TextBlock Text="An expander" Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Expander}}, Path=ActualWidth}" />
</Expander.Header>
<Button>A button</Button>
</Expander>
</Border>
</InlineUIContainer>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
</Window>
As for why, my code is based on this: http://stackoverflow.com/questions/3798262/how-to-collapse-a-paragraph although i've been improving it. The idea is add or remove a paragraph block below the expander block based on the state of the expander. That + code to handle the copy to clipboard to convert the uielements to text (in this case, getting the header string of the expander) and the result is an interactive flowdocument with collapsing regions and copy support.
modified 7-Nov-12 23:32pm.
|
|
|
|
|
I want my treeview items to change their appearance based on other properties within the object being represented by the treeview item. I've done the following within the treeview zaml:
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="Foreground" Value="{Binding Path=IsValid, Converter={StaticResource StatusInvalidConverter}}" />
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Border Grid.Column="0" x:Name="PART_ItemBorder" ... >
<StackPanel Orientation="Horizontal">
<Label Content="{Binding}" />
/// my custom stuff is here
<Label Content="(NOT USED)"
Visibility="{Binding Path=IsReferenced, Converter={StaticResource MyConverter}}"
Foreground="Red" />
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
I'm getting the following notification in the output window when I run the app in debug mode:
System.Windows.Data Error: 40 : BindingExpression path error: 'IsReferenced' property not found on 'object' ''String' (HashCode=1540110492)'. BindingExpression:Path=IsReferenced; DataItem='String' (HashCode=1540110492); target element is 'Label' (Name=''); target property is 'Visibility' (type 'Visibility')<br />
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
You've created a DataTemplate there which, in effect, altering changes the DataContext. An easy way to correct this is to use the RelativeSource to find it like this:
Visibility="{Binding Path=IsReferenced, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeView}}, Converter={StaticResource MyConverter}}"
|
|
|
|
|
I'm now getting the following message:
System.Windows.Data Error: 40 : BindingExpression path error: 'IsReferenced' property not found on 'object' ''TreeView' (Name='sceneTree')'. BindingExpression:Path=IsReferenced; DataItem='TreeView' (Name='sceneTree'); target element is 'Label' (Name=''); target property is 'Visibility' (type 'Visibility')<br />
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Oops! I forgot to put the DataContext in. This should sort it:
Visibility="{Binding Path=DataContext.IsReferenced, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeView}}, Converter={StaticResource MyConverter}}"
|
|
|
|
|
I came back here to tell you I added that (DataContext), and the messages went away, but the breakpoint in the converter isn't being hit.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Okay. Now WPF comes with a BooleanToVisibilityConverter built in so that you don't have to roll your own. if you change your reference to that one, I would expect it to change the visibility - I'm assuming here of course that IsReferenced is a boolean.
|
|
|
|
|
Yes, it is a bool, but I need the inverse of what BooleanToVisibility (if the bool is true, I want Visibility.Collapsed ) provides, so I rolled my own. Beyond that, I have another property that I'm trying to set that's exhibiting the same issue, and it converts from a bool to a color.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Ah, okay. So I take it that the converter isn't firing then.
|
|
|
|
|
At this point, apparently not. :/
The properties in question are read-only because they simply evaluate the contents of another object, so RaisePropertyChanged wasn't getting called. I added some functionality to call RaisePropertyChanged, but that didn't have any affect.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I tried adding some properties that did the work of the converters, and these properties are getting called (and returning the expected values, but the treeview items aren't changing...
Is it too soon to expound on my general distaste for WPF?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Hmmm. It sounds as though it's picking the "wrong" DataContext.
|
|
|
|
|
I think I have to re-examine my treeviewitem style. I think the triggers are overriding my intent.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Do you want to send it to my email address? I'll have a quick look if you like.
|
|
|
|
|
Let me bang on it some more today (I'm going to look at the triggers), and if I still end up being blocked, I'll let you know. And if I finger it out, I'll let you know.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Try substituting TreeViewItem for TreeView in the FindAncestor lookup. See if that gets the right instance?
|
|
|
|
|
I tried that yesterday (before changing to use properties instead of converters, but I'll try it again.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Well, I spent the morning creating a test app similar in architecture to the app I'm working on. I think this will make it easier to screw up.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
I fingered out what I was doing wrong. While creating the little sample app, I realized that since we're not data binding the tree, the DataContext for the tree (and its items) was NOT being set. We are creating each TreeViewItem individually, and as I was adding the code that did that, I wondered what would happen if I set the DataContext property to the object the item was representing.
When I set that, the tree lit up like a freakin' Christmas tree. I think I got a bit of a woody as a result (but I'm still not fond of WPF)...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
New Wrinkle...
So I transferred the new code to the actual project, and it still refused to work. The only difference between the actual project and my little sample app is that the TreeViewItem style was implemented inside the Window.xaml file in the sample app, but was in a ResourceDictionary in the application. I moved the style xaml to the actual control that contained the TreeView , did a clean/rebuild all, and it worked.
What an overly obscure pain in the ass...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|