Hi,
I have the following Xaml.. I'm not sure why I can't get the context
menu item's to bind to a property of the window. Any ideas?
Thanks
Andy
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication5.Window1"
xmlns:diagnostics="clr-
namespace:System.Diagnostics;assembly=WindowsBase"
xmlns:WpfApplication5="clr-namespace:WpfApplication5"
Height="250"
Width="250"
Title="Test Application"
>
<Window.Resources>
<BooleanToVisibilityConverter x:Key="VisConverter" />
</Window.Resources>
<x:Code>
<![CDATA[
public static readonly DependencyProperty IsSelectorProperty =
DependencyProperty.Register(
"IsSelector",
typeof( bool ),
typeof( Window1 ),
new PropertyMetadata( false )
);
public bool IsSelector {
get { return (bool)GetValue( IsSelectorProperty ); }
set { SetValue( IsSelectorProperty, value ); }
}
]]>
</x:Code>
<StackPanel>
<TextBlock Text="{Binding
diagnostics:PresentationTraceSources.TraceLevel=High, Path=IsSelector,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type
WpfApplication5:Window1}}}" />
<ListView
x:Name="PartListGrid"
Height="200"
Width="200"
>
<ListView.ContextMenu>
<ContextMenu x:Name="ContextMenu">
<MenuItem
x:Name="SelectMenuItem"
Header="Select"
Visibility="{Binding
diagnostics:PresentationTraceSources.TraceLevel=High,
Converter={StaticResource VisConverter}, Path=IsSelector,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type
WpfApplication5:Window1}}}"
/>
<Separator
Visibility="{Binding Converter={StaticResource
VisConverter},Path=IsSelector, RelativeSource={RelativeSource
FindAncestor, AncestorType={x:Type WpfApplication5:Window1}}}"
/>
<MenuItem
Header="Open"
/>
</ContextMenu>
</ListView.ContextMenu>
</ListView>
</StackPanel>
</Window>
|