Button 带子项的按钮上的样式

Button 带子项的按钮上的样式,button,windows-8.1,windows-phone-8.1,children,win-universal-app,Button,Windows 8.1,Windows Phone 8.1,Children,Win Universal App,我有一个关于风格的问题。在我的Windows通用应用程序中,我有一些按钮。这些按钮将stackpanel作为子按钮,stackpanel将图像作为子按钮。这样做的目的是按钮需要包含图像 现在我的雇主想忽略用户的主题设置。因此,无论何时单击按钮,他都不希望按钮的背景颜色发生变化。到目前为止,我发现要做到这一点,唯一的方法就是用一种风格。但是,当我使用样式时,按钮显示时没有子项。我制作的样式如下所示: <Style x:Key="Button_style" TargetType="Button

我有一个关于风格的问题。在我的Windows通用应用程序中,我有一些按钮。这些按钮将stackpanel作为子按钮,stackpanel将图像作为子按钮。这样做的目的是按钮需要包含图像

现在我的雇主想忽略用户的主题设置。因此,无论何时单击按钮,他都不希望按钮的背景颜色发生变化。到目前为止,我发现要做到这一点,唯一的方法就是用一种风格。但是,当我使用样式时,按钮显示时没有子项。我制作的样式如下所示:

<Style x:Key="Button_style" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Pressed">
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                    <VisualState x:Name="PointerOver">
                                    </VisualState>
                                    <VisualState x:Name="Pointerleave">
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused"/>
                                    <VisualState x:Name="PointerFocused"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

这是一个概念证明。然而,由于按钮的孩子们消失了,我无法继续下去。我该如何改写这种风格,让按钮的孩子们留在他们应该呆的地方

以下是我拥有的按钮的一些示例代码:

<Button Name="MyButton" Click="MyButton_Click" ClickMode="Press" HorizontalAlignment="Center" VerticalAlignment="Stretch" >  
    <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left" >
         <Image Name="MyImage" x:Uid="MyImage" Source="" VerticalAlignment="Top" HorizontalAlignment="Left" MaxWidth="30" />
     </StackPanel>
</Button>

如果您想完全忽略用户设置,最好的选择是覆盖PhoneAccentBrush值。您可以在App.xaml中执行此操作,也可以使用ResourceDistory

  <Color x:Key="PhoneAccentColor">Blue</Color>
蓝色
也可以在App.xaml中为您的应用程序请求明暗主题:

  <Application x:Class="App1.App"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:local="using:App2"
               RequestedTheme="Light">
  </Application>


嘿,谢谢。我试试这个。但这可能只适用于项目的电话部分。windows modern应用程序也有类似的功能吗?你是对的。这将只适用于手机。在商店应用程序中,您可以覆盖按钮PressedBackgroundTheMerrush资源。但这与其他控件不同。以下是资源的完整列表: