xaml - Binding MenuItem property (IsEnabled) to combobox property (SelectedIndex) in same control -


I have spent a good part of my research; I'm curious if it is possible to make a completely simple binding in XAM, without the need to implement the InoPayPropt change without code.

Ironically, how much time has I spent researching this, I did just 5 times behind the code.

I have come across some articles which suggest using the DataTrigger (for menu items, the data trigger should be within a style trigger). I have tried this, but it does not work without error.

I suspect that the DataTrigger could not find the combo box due to issues of menu scope, which I read in a different thread.

Anyone have any suggestions?

Code: (There are no build or runtime errors, but property is not updated)

  & lt; ContextMenu & gt; & Lt; MenuItem header = "Fix something" x: name = "MyMenuItem" click = "MyMenuItem_Click" & gt; & Lt; MenuItem.Style & gt; & Lt; Style TargetType = "{x: type menu item}" & gt; & Lt; Style.Triggers & gt; & Lt; Setter Property = "Iceded" value = "true" /> & Lt; Datatrigger binding = "{binding element name = mycombobox, path = selected index}" value = "- 1" & gt; & Lt; Setter property = "iced" value = "wrong" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /MenuItem.Style> & Lt; / MenuItem & gt; & Lt; / ContextMenu & gt;  

I moved the default setter to Style.Triggers (due to a compilation error), put everything in a menu (to simplify the example) and index it to 0 (better performance result Triggered on). Do the following:

& lt; Window x: Class = "WpfApplication1.MainWindow" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "title =" main window "height =" 350 "width =" 525 "& gt; & Lt; DocPanel Last ChildFill = "False" & gt; & Lt; Menu height = "23" dock panel Doc = "top" & gt; & Lt; MenuItem Header = "Something Slack" & gt; & Lt; MenuItem.Style & gt; & Lt; Style TargetType = "{x: type menu item}" & gt; & Lt; Setter Property = "Iceded" value = "true" /> & Lt; Style.Triggers & gt; & Lt; Datatrigger binding = "{binding element name = mycombobox, path = selected index}" value = "0" & ​​gt; & Lt; Setter property = "iced" value = "wrong" /> & Lt; / DataTrigger & gt; & Lt; /Style.Triggers> & Lt; / Style & gt; & Lt; /MenuItem.Style> & Lt; / MenuItem & gt; & Lt; / Menu & gt; & Lt; Combo box name = "mycombobox" height = "23" width = "120" dock panel Doc = "top" & gt; & Lt; Combo box item & gt; Index 0 & lt; / Combo box item & gt; & Lt; Combo box item & gt; Index 1 & lt; / ComboBoxItem & gt; & Lt; / ComboBox & gt; & Lt; / DockPanel & gt; & Lt; / Window & gt;

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -