PC Review


Reply
Thread Tools Rate Thread

Binding from ContextMenu

 
 
Andy
Guest
Posts: n/a
 
      8th Oct 2008
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>
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with binding to binding source on base form in VS 2005 =?Utf-8?B?SmltIFRpbHNvbg==?= Microsoft Dot NET Framework Forms 3 17th Oct 2006 12:19 PM
>> Early binding and late binding with attachment =?Utf-8?B?Sm9uYXRoYW4=?= Microsoft Outlook VBA Programming 2 9th Jun 2006 02:24 AM
Late Binding examples of binding excel application =?Utf-8?B?SGVhdGhlck8=?= Microsoft Excel Programming 14 17th Mar 2005 08:19 AM
Is it possible to add ContextMenu items to the Standard TextBox ContextMenu??? =?Utf-8?B?TWlrZSBpbiBQYXJhZGlzZQ==?= Microsoft Dot NET Framework Forms 1 15th Mar 2004 07:54 AM
Re: Data Binding - using inline code vs. functions vs. straight binding Alvin Bruney [MVP] Microsoft ASP .NET 0 9th Mar 2004 01:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:51 AM.