我想在UWP中为主细节页面设置Page Button的样式。在Live Visual Tree的帮助下,我发现它应该是ContentTogglePane
button。如何在UWP的主细节页面中更改页面按钮的样式
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Background="{TemplateBinding ToolbarBackground}" >
<Button Name="ContentTogglePane" Style="{ThemeResource PaneButton}" Foreground="{TemplateBinding ToolbarForeground}"
Visibility="{TemplateBinding ContentTogglePaneButtonVisibility}" />
<Border Height="{ThemeResource TitleBarHeight}" Visibility="{TemplateBinding DetailTitleVisibility}">
<TextBlock Text="{TemplateBinding DetailTitle}" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="{TemplateBinding ToolbarForeground}" Style="{ThemeResource TitleTextBlockStyle}" />
</Border>
</StackPanel>
风格在this way定义:
<Style TargetType="Button" x:Key="PaneButton">
<Setter Property="FontFamily" Value="{ThemeResource SymbolThemeFontFamily}" />
<Setter Property="FontSize" Value="20" />
<Setter Property="Height" Value="48" />
<Setter Property="Width" Value="48" />
<Setter Property="Content" Value="" />
</Style>
我试图修改除了ContentTogglePane
按钮default button style和所有其他按钮的变化。我想删除边框并更改悬停上的文字颜色以及背景。
我必须覆盖哪种风格才能完成此操作?理想情况下,只有ContentTogglePane
按钮被覆盖。
你在'ControlTemplate'改变了'BorderBrush'的'Foreground'并添加'Background'为'PointerOver'。更有趣的是,您添加了'MasterDetailControl'并将'PaneButton'分配给了我们的新样式。你在哪里从MasterDetailControl获得样式?还有一个问题:如果我使用'MergedDictionaries'将'MasterDetailControl'的样式放入单独的XAML中,为什么它不起作用?我可以将按钮样式放在单独的XAML中,但不能用于“MasterDetailControl”。 – testing
我只找到[MasterDetailControlStyle](https://github.com/xamarin/Xamarin.Forms/blob/74cb5c4a97dcb123eb471f6b1dffa1267d0305aa/Xamarin.Forms.Platform.UAP/MasterDetailControlStyle.xaml),但它与您的答案中的样式不匹配。 – testing
@testing,哦,我忘记在我的回答中提到这一点,因为我使用了xamarin的稳定版本2.3.2,所以我需要在这个版本中使用相应的样式,并且它在[Resources.xaml](https ://github.com/xamarin/Xamarin.Forms/blob/2.3.2/Xamarin.Forms.Platform.UAP/Resources.xaml),而不是像在以后的版本中那样在一个单独的xaml文件中。请注意Github上不同的xamarin版本的不同分支。 –