Binding from ContextMenu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy

    Binding from ContextMenu

    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.microso ft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microso ft.com/winfx/2006/xaml"
    x:Class="WpfApp lication5.Windo w1"
    xmlns:diagnosti cs="clr-
    namespace:Syste m.Diagnostics;a ssembly=Windows Base"
    xmlns:WpfApplic ation5="clr-namespace:WpfAp plication5"
    Height="250"
    Width="250"
    Title="Test Application"
    >
    <Window.Resourc es>
    <BooleanToVisib ilityConverter x:Key="VisConve rter" />
    </Window.Resource s>

    <x:Code>
    <![CDATA[
    public static readonly DependencyPrope rty IsSelectorPrope rty =
    DependencyPrope rty.Register(
    "IsSelector ",
    typeof( bool ),
    typeof( Window1 ),
    new PropertyMetadat a( false )
    );

    public bool IsSelector {
    get { return (bool)GetValue( IsSelectorPrope rty ); }
    set { SetValue( IsSelectorPrope rty, value ); }
    }

    ]]>
    </x:Code>

    <StackPanel>
    <TextBlock Text="{Binding
    diagnostics:Pre sentationTraceS ources.TraceLev el=High, Path=IsSelector ,
    RelativeSource= {RelativeSource FindAncestor, AncestorType={x :Type
    WpfApplication5 :Window1}}}" />
    <ListView
    x:Name="PartLis tGrid"
    Height="200"
    Width="200"
    >
    <ListView.Conte xtMenu>
    <ContextMenu x:Name="Context Menu">
    <MenuItem
    x:Name="SelectM enuItem"
    Header="Select"
    Visibility="{Bi nding
    diagnostics:Pre sentationTraceS ources.TraceLev el=High,
    Converter={Stat icResource VisConverter}, Path=IsSelector ,
    RelativeSource= {RelativeSource FindAncestor, AncestorType={x :Type
    WpfApplication5 :Window1}}}"
    />
    <Separator
    Visibility="{Bi nding Converter={Stat icResource
    VisConverter},P ath=IsSelector, RelativeSource= {RelativeSource
    FindAncestor, AncestorType={x :Type WpfApplication5 :Window1}}}"
    />
    <MenuItem
    Header="Open"
    />
    </ContextMenu>
    </ListView.Contex tMenu>
    </ListView>
    </StackPanel>
    </Window>
Working...