Skip to main content
 首页 » 编程设计

c#之如何在 Windows 10 应用程序中动态更改 Split View背景颜色

2024年02月05日12myhome

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
        <SplitView x:Name="mySplitView" DisplayMode="CompactInline"  IsPaneOpen="False"  
                CompactPaneLength="50" OpenPaneLength="150" Content="{Binding}"> // using PaneBackground I can set color statically 
            <SplitView.Pane> 
                <StackPanel> 
                    <Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="&#xE700;" 
                     Width="50" Height="50" Background="Transparent" Foreground="White"  Click="HamburgerButton_Click" /> 
            <StackPanel> 
         </SplitView.Pane> 
     </SplitView> 
 </Grid> 

。如何动态更改 Splitview Pane 的颜色,即如果用户单击按钮将颜色更改为黄色,它应该更改,如果用户想要默认的强调色,那么应该像在 outlook 邮件应用程序中一样设置。我在一个页面中有我的 Split View,并且想要其他 xaml 页面中的按钮,即设置页面。

请您参考如下方法:

您可以使用“PaneBackground”属性作为代码,并在每个项目的单击事件处理程序中使用此代码:

mySplitView.PaneBackground = new SolidColorBrush(Colors.Yellow);  

这是您尝试做的吗?