0
votes

I'm trying to modify ToggleButton Command when it cahnges it's IsChecked property. My XAML looks like this:

<ToggleButton  Content="Profile" Command="{Binding Path=ShowProfileMappingCommand}" CommandParameter="{Binding Path=ProfileMappingParameter}">
                <ToggleButton.Style>
                    <Style TargetType="ToggleButton">
                        <Style.Triggers>
                            <Trigger Property="IsChecked" Value="True">
                                <Setter  Property="Command"  Value="{Binding Path=ShowProfileMappingCommand}" />
                            </Trigger>
                            <Trigger Property="IsChecked" Value="False">
                                <Setter  Property="Command"  Value="{Binding Path=HideProfileMappingCommand}" />
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </ToggleButton.Style>
            </ToggleButton>

Unfortunately, this doesn't seem to work. My Commands never get called. Any ideas why this might be the case?

1
Why don't you just pass the Bool IsChecked property as the command parameter? Looks like you're overcomplicating this by having 2 different commands, IMO;Federico Berasategui
You could create a property in your ViewModel called IsChecked. Then in XAML, bind your IsChecked property of the ToggleButton to the IsChecked property in your ViewModel. In the setter portion of the property, check if value == true. This way, all the logic falls in the setter the property that the control is bound to in the ViewModel.kformeck
@HighCore Good point. I'll think about it.L.E.O

1 Answers

0
votes

IMO I agree with HighCore that this seems over complicated. However, if this must be done like you have it (which I would guess is possible to do) then, just a guess, try a relative source bind like:

Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.ShowProfileMappingCommand}"

Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=DataContext.HideProfileMappingCommand}"

Idk if this xaml is in a usercontrol or page, you will have to change the ancestorType to the type of control your using here. This may or may not help.

Setting inline: Command="{Binding Path=ShowProfileMappingCommand}" may potentially cause problems too at the same time using datatriggers.