I want to create a group of togglebuttons that zero or one toggle button checked at a time.
If i use a radiobutton with togglebutton style then atleast one togglebutton will be checke at a specifiec time and I want to allow the option that no togglebutton will be checked.
I created the following style to a togglebutton and the following togglebuttons but for some reason the togglebutton doesn't change the ischecked property when invoked.
<Window x:Class="ClearMvvmDeltaItem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Model="clr-namespace:ClearMvvmDeltaItem.Model" Title="MainWindow"
Height="300"
Width="300"
DataContext="{Binding Main, Source={StaticResource Locator}}">
<Window.Resources>
<Model:NotConverter x:Key="NotConverter" />
<Style TargetType="{x:Type CheckBox}">
<Style.Triggers>
<DataTrigger Value="False">
<DataTrigger.Binding>
<MultiBinding Converter="{StaticResource NotConverter}" UpdateSourceTrigger="PropertyChanged">
<Binding RelativeSource="{RelativeSource Mode=Self}" Path="Name"></Binding>
<Binding Path="CurrentCheckedItem"></Binding>
</MultiBinding>
</DataTrigger.Binding>
<DataTrigger.Setters>
<Setter Property="Background" Value="Red"></Setter>
<Setter Property="IsChecked" Value="False"></Setter>
</DataTrigger.Setters>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<CheckBox x:Name="first" Content="First"
Command="{Binding FirstCheckedChanged}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Name}"
IsChecked="{Binding IsFirstChecked }"
>
</CheckBox>
<CheckBox x:Name="second" Command="{Binding SecondCheckedChanged}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Name}"
IsChecked="{Binding IsSecondChecked}"
Content="Second"
Grid.Row="1"></CheckBox>
<CheckBox x:Name="third" Content="Third" Grid.Row="2"
Command="{Binding ThirdCheckedChanged}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Name}"
IsChecked="{Binding IsThirdChecked}"
></CheckBox>
</Grid>
Viewmodel command code:
FirstCheckedChanged = new RelayCommand<string>(newName =>
{
if (_isFirstChecked)
CurrentCheckedItem = newName;
});
SecondCheckedChanged = new RelayCommand<string>(newName =>
{
if (_isSecondChecked)
CurrentCheckedItem = newName;
});
ThirdCheckedChanged = new RelayCommand<string>(newName =>
{
if (_isThirdChecked)
CurrentCheckedItem = newName;
});
The datatrigger is invoked because i can see that the background color of the relevant togglebuttons changed to red but the ischecked property isn't affected at all.
Thanks...