|
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
|
|
|
|
|
how to create slide menu in wpf?
|
|
|
|
|
I asked Google your question, and got these[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Dear Sir/Madam,
I am using DevExpress dxGridControl for viewing data. I used customized scrollbar in it.
Vertical scrollbar is working fine but Horizontal scrollbar is not working properly.
The Horizontal scrollbar is not customized & even though it is having issue of scrolling. For resolving this issued I replace Horizontal Scrollbar code with Normal horizontal scrollbar code, but not succeeded.
For more clarification please find Image at https://www.sugarsync.com/pf/D8670380_68034791_25743.
The sample project is also uploaded at SugarSync link of it is https://www.sugarsync.com/pf/D8670380_68034791_25575
Kindly guide me how to resolve it.
Thanks & Regards
|
|
|
|
|
I need to add two TextBlocks to each TreeView item, and have them be right-justified in the tree (in other words, butted up against the right side of the tree.
I've tried the following (this is the TreeView xaml), and I get the desired TextBlocks, but the are right next to the TreeViewItem itself.
<TreeView Name="sceneTree"
ItemContainerStyle="{DynamicResource SceneTreeItemStyle}"
PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown">
<TreeView.Resources>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderThickness="2,0,0,0" BorderBrush="Transparent"
Background="Transparent" x:Name="PART_ItemBorder" Margin="0"
Padding="1,0,0,0" HorizontalAlignment="Stretch">
<Label Content="{Binding}" />
</Border>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock Text=" ? " FontFamily="Arial" FontWeight="ExtraBlack" Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
<TextBlock Text=" X " FontFamily="Arial" FontWeight="ExtraBlack" Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</TreeView.Resources>
</TreeView>
The SceneTreeItemStyle looks like this (and the two TextBlock objects are displaying where I want them):
<Style x:Key="SceneTreeItemStyle" TargetType="{x:Type TreeViewItem}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="HorizontalContentAlignment"
Value="{Binding HorizontalContentAlignment,
RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment"
Value="{Binding VerticalContentAlignment,
RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Padding" Value="1,0,0,0"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource TreeViewItemFocusVisual}"/>
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
<Setter Property="FontWeight" Value="Normal" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TreeViewItem}">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="19" Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ToggleButton x:Name="Expander" ClickMode="Press"
IsChecked="{Binding IsExpanded,
RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ExpandCollapseToggleStyle}"/>
<Border x:Name="Bd"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Grid.Column="1" Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter x:Name="PART_Header" ContentSource="Header"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ItemsPresenter x:Name="ItemsHost" Grid.ColumnSpan="3" Grid.Column="1"
Grid.Row="1" HorizontalAlignment="Stretch" />
<StackPanel Orientation="Horizontal" Grid.Column="3" HorizontalAlignment="Right">
<TextBlock Text=" ? " FontFamily="Arial" FontWeight="ExtraBlack"
Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
<TextBlock Text=" X " FontFamily="Arial" FontWeight="ExtraBlack"
Background="Yellow" Foreground="Red" VerticalAlignment="Center" />
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Can anyone help?
".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'm not quite sure I get your question... but I'm assuming you are getting something like:
<tree view item>? X
and you want something like:
<tree view item> ? X
TreeViewItems don't stretch horizontally by default, so that's why you get the first version above. If you want the 2nd version (i.e. a "multi-column" tree view item), you'd need to stretch the TreeViewItem horizontally and fake the selection rectangle.
You are going to run into a bunch of alignment issues, so I'd suggest finding a real WPF multi-column TreeView control and using that, so items are properly aligned and clipped and thus your ? and X will be aligned properly.
|
|
|
|
|
I am using a list box in WPF. I allowed the users to paste the data to the listbox. I used the following if statement to check if users pressed Ctrl-V:
if (e.Key == Key.V && Keyboard.Modifiers == ModifierKeys.Control){}
But this if statement does not work if users pressed Ctrl and V at the same time. If users pressed the Ctrl and V at the same time, Key will be LeftCtrl and Keyboard.Modifiers will be none.
Thanks.
|
|
|
|
|
Rather than trying to brute force the paste handler, why not use DataObject.AddPastingHandler(MyListBox, OnClipboardPaste); to hook up a paste handler to your listbox?
|
|
|
|
|