有趣的。该问题实际上是由于BladeItem
某种原因的默认样式引起的。
由于您已经设置TitleBarVisibility
为Collapsed
,因此修复此问题非常简单。您只需将以下样式应用于您的BladeItem
. 这个和默认的唯一区别是内部Grid
被注释掉了。是的,这就是问题所在。
<Style x:Key="MyBladeStyle" TargetType="controls:BladeItem">
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="TabNavigation" Value="Local" />
<Setter Property="IsHoldingEnabled" Value="True" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Margin" Value="0" />
<Setter Property="MinWidth" Value="{ThemeResource GridViewItemMinWidth}" />
<Setter Property="MinHeight" Value="{ThemeResource GridViewItemMinHeight}" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:BladeItem">
<Grid BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!--<Grid Background="{TemplateBinding TitleBarBackground}"
Visibility="{TemplateBinding TitleBarVisibility}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Margin="4,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="{TemplateBinding TitleBarForeground}"
Text="{TemplateBinding Title}" />
<Button Name="CloseButton"
Grid.Column="1"
TabIndex="0"
HorizontalAlignment="Right"
AutomationProperties.Name="Cancel"
Background="{TemplateBinding CloseButtonBackground}"
Content=""
FontFamily="Segoe MDL2 Assets"
Foreground="{TemplateBinding CloseButtonForeground}" />
</Grid>-->
<ContentPresenter Grid.Row="1"
VerticalAlignment="Stretch"
Background="{TemplateBinding Background}"
Visibility="{TemplateBinding IsOpen}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
更新
好的,经过一番挖掘,我发现真正的问题实际上在于BladeItem
-TitleBarForeground
和CloseButtonForeground
. 这可能是一个 UWP 错误,因为解决方法很简单,只需为它们提供一些默认值(请参阅下面的 xaml 代码),尽管它们的依赖项属性声明中已经设置了相同的默认值。
<!-- Add the following to the default style -->
<Setter Property="TitleBarForeground" Value="Black" />
<Setter Property="CloseButtonForeground" Value="Black" />
现在注意上面的两行代码,你不再需要注释掉内部的Grid
.