[WPF] Binding ItemsSource to Enum

2
Comments

Suppose you need to bind ItemsSource dependency property to enum's values. For example in ComboBox. You have following enum: public enum ExampleEnum { Red, Green, Yellow } Now you can use ObjectDataProvider <Window x:Class="ExampleApplication.Window" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace...

Read further...

[WPF] ContextMenu Commnad binding issue fixed

0
Comments

If there is no focused element in the window's main focus scope, the CanExecute routing will stop at the ContextMenu, so it will not reach to the CommandBinding on the Window, one workaround is to bind MenuItem's CommandTarget to the main window. <ContextMenu > <ContextMenu.Items> <MenuItem Command="ApplicationCommands.Open" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"/> </ContextMenu.Ite...

Read further...

WPF Binding examples

2
Comments

I have found very nice WPF XAML Data Binding Cheat Sheet, so I'll just leave it here for further use. Basic Binding {Binding} Bind to current DataContext. {Binding Name} Bind to the “Name” property of the current DataContext. {Bindind Name.Length} Bind to the Length property of the object in the Name property of the current DataContext. {Binding ElementName=SomeTextBox, Path=Text} Bind to the “Text” property of the element XAML element with name=”SomeTextBox” or x:Name=”SomeTextBox”. XML Binding...

Read further...