Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top