Style is only applying to two elements
I have a ToogleButton whose Content I am changing with DataTriggers this way:
<Style x:Key="EstiloToggleButton" TargetType="ToggleButton"
BasedOn="{StaticResource {x:Type ToggleButton}}">
<Setter Property="BorderBrush" Value="#FF333333" />
<Style.Triggers>
<DataTrigger Binding="{Binding
RelativeSource={RelativeSource Self}, Path=IsChecked}"
Value="True">
<Setter Property="BorderBrush" Value="#FFFF8000" />
<Setter Property="Content">
<Setter.Value>
<TextBlock Text="p" FontFamily="Wingdings 3"
RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.5"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource
Self}, Path=IsChecked}" Value="False">
<Setter Property="Content">
<Setter.Value>
<TextBlock Text="q" FontFamily="Wingdings 3"
RenderTransformOrigin="0.5,0.5">
<TextBlock.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleY="0.5"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
This is how it looks:
Previously I've defined this for each button and everything worked great,
but It was a lot of lines of code, so I decided to condense it in a style,
and then apply the same style to all my ToggleButtons with that desired
look.
So far so good, but now I have a problem: only one, or sometimes two
ToggleButtons are working correctly at the same time, the rest are in
blank:
Somehow the buttons are interfering to each other. Is that possible
because of the style?
I have some some ugly code behind, because I need to display a Popup below
the button in a special way (not easy to achieve in XAML)
//Popup FFT
private void visButtonFFT_Checked(object sender, RoutedEventArgs e)
{
popupFFT.IsOpen = true;
}
private void visButtonFFT_Unchecked(object sender, RoutedEventArgs e)
{
popupFFT.IsOpen = false;
}
private void popupFFT_Closed(object sender, EventArgs e)
{
visButtonFFT.IsChecked = false;
}
I have this code for each ToggleButton (not clever, I know, but I'm still
learning)
Do you something that can cause this strange behavior? Thanks.
EDIT: The only thing that I've changed when I moved the style from the
particular ToggleButton to the resources of the UserControl is the Binding
of the DataTrigger: it was targeting the actual name of the button, and I
had to change it to the RelativeSource.
No comments:
Post a Comment