これでToggleButton
スタイルができました。次に、非表示Chrome.Visibility = Visibility.Hidden
のように見えますが、そうToggleButton
ではありません。
スヌープを使用して、 が表示されていることを確認ToggleButton's
Visibility
します。ToggleButton's
スタイルで可視性を変更するにはどうすればよいですか?
スタイルは次のとおりです。
<Style x:Key="ToggleButtonStyle"
TargetType="{x:Type ToggleButton}">
<Setter Property="FocusVisualStyle"
Value="{StaticResource ButtonFocusVisual}" />
<Setter Property="Background"
Value="{StaticResource ButtonNormalBackground}" />
<Setter Property="BorderBrush"
Value="{StaticResource ButtonNormalBorder}" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="HorizontalContentAlignment"
Value="Center" />
<Setter Property="VerticalContentAlignment"
Value="Center" />
<Setter Property="Padding"
Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<ControlTemplate.Resources>
<Storyboard x:Key="go">
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
Storyboard.TargetName="grid">
<DiscreteObjectKeyFrame KeyTime="0:0:0.5"
Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)"
Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0:0:0.5"
Value="720" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0:0:0.5"
Value="0.15" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
Storyboard.TargetName="grid">
<EasingDoubleKeyFrame KeyTime="0:0:0.5"
Value="0.15" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</ControlTemplate.Resources>
<Grid x:Name="grid"
RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform />
<SkewTransform />
<RotateTransform />
<TranslateTransform />
</TransformGroup>
</Grid.RenderTransform>
<Border x:Name="Chrome"
BorderThickness="5"
CornerRadius="10"
BorderBrush="#FFD7FF25"
Grid.ColumnSpan="2">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<Button x:Name="button"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Height="16.333"
Width="Auto"
Background="#FFD7FF25"
Foreground="#FFFF0B0B"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
BorderBrush="#FFD7FF25"
Padding="0,-6,0,0"
FontSize="16"
Margin="0,-4.167,-3.334,0"
Content="x"
Focusable="False"
Visibility="Collapsed"
Click="Button_OnClick"
BorderThickness="1" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True"
SourceName="grid">
<Setter Property="Visibility"
TargetName="button"
Value="Visible" />
<Setter Property="BorderBrush"
TargetName="Chrome"
Value="#FF4DFF25" />
<Setter Property="BorderBrush"
TargetName="button"
Value="#FF4DFF25" />
<Setter Property="Background"
TargetName="button"
Value="#FF4DFF25" />
</Trigger>
<EventTrigger RoutedEvent="ButtonBase.Click"
SourceName="button">
<BeginStoryboard x:Name="go_BeginStoryboard"
Storyboard="{StaticResource go}" />
</EventTrigger>
<Trigger Property="IsChecked"
Value="true">
<Setter Property="BorderBrush"
TargetName="Chrome"
Value="Red" />
</Trigger>
<Trigger Property="IsEnabled"
Value="false">
<Setter Property="Foreground"
Value="#ADADAD" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
マウスオンするとToggleButton
が表示されますので、クリックすると消えます。Button
X
ToggleButton
Note:
を 1 つ以上入れるとToggleButton
、の前に空白が見えます。WrapPanel
WrapPanel