我想在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版本的不同分支。 –