fix: make content invisible when content is null.

This commit is contained in:
rabbitism
2023-02-24 00:16:58 +08:00
parent 4fc1dc5949
commit ef9455c6da

View File

@@ -30,6 +30,8 @@
VerticalAlignment="Top" VerticalAlignment="Top"
Content="{TemplateBinding Content}" Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplate="{TemplateBinding ContentTemplate}"
IsVisible="{TemplateBinding Content,
Converter={x:Static ObjectConverters.IsNotNull}}"
RecognizesAccessKey="True" /> RecognizesAccessKey="True" />
<Grid <Grid
Grid.Row="1" Grid.Row="1"
@@ -123,22 +125,17 @@
<Setter Property="ContentPresenter.IsVisible" Value="True" /> <Setter Property="ContentPresenter.IsVisible" Value="True" />
</Style> </Style>
<Style Selector="^ /template/ Border#SwitchBackgroundBorder"> <Style Selector="^ /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedDefaultBackground}" />
Value="{DynamicResource ToggleSwitchContainerUnCheckedDefaultBackground}" />
</Style> </Style>
<Style Selector="^:pointerover /template/ Border#SwitchBackgroundBorder"> <Style Selector="^:pointerover /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedPointerOverBackground}" />
Value="{DynamicResource ToggleSwitchContainerUnCheckedPointerOverBackground}" />
</Style> </Style>
<Style Selector="^:pressed /template/ Border#SwitchBackgroundBorder"> <Style Selector="^:pressed /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedPressedBackground}" />
Value="{DynamicResource ToggleSwitchContainerUnCheckedPressedBackground}" />
</Style> </Style>
<Style Selector="^:disabled /template/ Border#SwitchBackgroundBorder"> <Style Selector="^:disabled /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedDisabledBackground}" />
Value="{DynamicResource ToggleSwitchContainerUnCheckedDisabledBackground}" /> <Setter Property="Border.BorderBrush" Value="{DynamicResource ToggleSwitchContainerUnCheckedDisabledBorderBrush}" />
<Setter Property="Border.BorderBrush"
Value="{DynamicResource ToggleSwitchContainerUnCheckedDisabledBorderBrush}" />
<Setter Property="Border.BorderThickness" Value="1" /> <Setter Property="Border.BorderThickness" Value="1" />
</Style> </Style>
</Style> </Style>
@@ -151,36 +148,33 @@
<Setter Property="ContentPresenter.IsVisible" Value="False" /> <Setter Property="ContentPresenter.IsVisible" Value="False" />
</Style> </Style>
<Style Selector="^ /template/ Border#SwitchBackgroundBorder"> <Style Selector="^ /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedDefaultBackground}" />
Value="{DynamicResource ToggleSwitchContainerCheckedDefaultBackground}" />
</Style> </Style>
<Style Selector="^:pointerover /template/ Border#SwitchBackgroundBorder"> <Style Selector="^:pointerover /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedPointerOverBackground}" />
Value="{DynamicResource ToggleSwitchContainerCheckedPointerOverBackground}" />
</Style> </Style>
<Style Selector="^:pressed /template/ Border#SwitchBackgroundBorder"> <Style Selector="^:pressed /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedPressedBackground}" />
Value="{DynamicResource ToggleSwitchContainerCheckedPressedBackground}" />
</Style> </Style>
<Style Selector="^:disabled /template/ Border#SwitchBackgroundBorder"> <Style Selector="^:disabled /template/ Border#SwitchBackgroundBorder">
<Setter Property="Border.Background" <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedDisabledBackground}" />
Value="{DynamicResource ToggleSwitchContainerCheckedDisabledBackground}" />
</Style> </Style>
</Style> </Style>
</ControlTheme> </ControlTheme>
<ControlTheme x:Key="ButtonToggleSwitch" BasedOn="{StaticResource {x:Type ToggleSwitch}}" TargetType="ToggleSwitch"> <ControlTheme
x:Key="ButtonToggleSwitch"
BasedOn="{StaticResource {x:Type ToggleSwitch}}"
TargetType="ToggleSwitch">
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="ToggleSwitch"> <ControlTemplate TargetType="ToggleSwitch">
<Border <Border
Name="Background" Name="Background"
Cursor="Hand"
Padding="8" Padding="8"
Background="{TemplateBinding Background}" Background="{TemplateBinding Background}"
CornerRadius="3"> CornerRadius="3"
<Grid Cursor="Hand">
Background="Transparent" <Grid Background="Transparent" ColumnDefinitions="Auto">
ColumnDefinitions="Auto">
<Grid x:Name="PART_SwitchKnob" /> <Grid x:Name="PART_SwitchKnob" />
<Grid x:Name="PART_MovingKnobs" /> <Grid x:Name="PART_MovingKnobs" />
<ContentPresenter <ContentPresenter
@@ -205,7 +199,10 @@
</Style> </Style>
</ControlTheme> </ControlTheme>
<ControlTheme x:Key="SimpleToggleSwitch" BasedOn="{StaticResource {x:Type ToggleSwitch}}" TargetType="ToggleSwitch"> <ControlTheme
x:Key="SimpleToggleSwitch"
BasedOn="{StaticResource {x:Type ToggleSwitch}}"
TargetType="ToggleSwitch">
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="ToggleSwitch"> <ControlTemplate TargetType="ToggleSwitch">
<Grid <Grid