I have binded an object to a WPF control. How can I toggle the object property “IsEditMode” on click of the edit button using only xaml and no code behind? Here is sample code of xaml –
<Label Style="{StaticResource TitleLabel}"
Content="{Binding Path=GroupTitle}"
Visibility="{Binding Path=IsEditMode, Converter={StaticResource boolToVis}}"
HorizontalAlignment="Left" />
<Button Content="Edit" HorizontalAlignment="Right" VerticalAlignment="Center">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<!--Toggle the bindedobject.IsEditMode property of click of button-->
</EventTrigger>
</Button.Triggers>
</Button>
I don’t think it’s possible with no C# (or VB) code at all, but you can do it with no code-behind, using the MVVM pattern. So you will have C# code, just not in the code-behind…
If you go this way, you need to expose a command from your ViewModel:
And bind your button to that command: