C# 更改windows phone通用应用程序中内容对话框按钮的样式
我在xaml中定义了此内容对话框:C# 更改windows phone通用应用程序中内容对话框按钮的样式,c#,xaml,windows-phone-8.1,styles,win-universal-app,C#,Xaml,Windows Phone 8.1,Styles,Win Universal App,我在xaml中定义了此内容对话框: <ContentDialog x:Name="AlertMessage" Background="#363636" IsSecondaryButtonEnabled="True" SecondaryButtonText="Cancel" IsPrimaryButtonEnabled="True" PrimaryButtonText="Ok" > <ContentDialog.Content>
<ContentDialog x:Name="AlertMessage" Background="#363636" IsSecondaryButtonEnabled="True" SecondaryButtonText="Cancel" IsPrimaryButtonEnabled="True" PrimaryButtonText="Ok" >
<ContentDialog.Content>
<StackPanel Name="rootStackPanel" Height="Auto" >
<StackPanel Margin="0">
<StackPanel Margin="0,0,0,10" Orientation="Horizontal">
<TextBlock x:Name="HeadingText" x:FieldModifier="public" Style="{StaticResource ApplicationMessageBoxHeadingStyle}" Text="Alert" />
<Image Margin="10,05,0,0" Source="/Assets/Images/alert.png" Width="35"></Image>
</StackPanel>
<TextBlock x:FieldModifier="public" x:Name="ContentText" Style="{StaticResource ApplicationMessageBoxErrorStyle}" Text="Are you sure you want to log off ?" />
</StackPanel>
</StackPanel>
</ContentDialog.Content>
</ContentDialog>
问题:是我的应用程序中的所有按钮都有一个样式。我还想对该对话框的主按钮和次按钮应用相同的样式。我不知道怎样才能做到这一点。是否可以将样式应用于这些按钮?ContentDialog按钮不可自定义,但您可以不设置ContentDialog的主按钮和辅助按钮,并在模板中添加自己的按钮。您可以间接自定义按钮。 ContentDialog的按钮使用目标类型“按钮”的“默认”样式。您可以覆盖SDK的ContentDialog样式,并在模板的Setter中添加不同的按钮样式。此按钮样式仅在ContentDialog控件的范围内有效 在本例中,新按钮样式需要放在第一个边框元素中(x:Name=“Container”)
如果您想更改ContendDialog PrimaryButton设置,您需要在ContenDialog.Resources中设置一个样式,该样式仅用于设置按钮和属性为“”且值为“”的设置器,下面就是一个示例
Converter={StaticResource StringEmptyToBoolConverter}}"
<ContentDialog.Resources>
<converters:StringEmptyToBoolConverter x:Key="StringEmptyToBoolConverter"/>
<Style TargetType="Button">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FontSize" Value="13.6"/>
<Setter Property="Width" Value="Auto"/>
</Style>
</ContentDialog.Resources>
<WebView Height="400" Width="500" DefaultBackgroundColor="Transparent" Source="{Binding State.GuideUri}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="RulesWebView"/>
Converter={staticResourceStringEmptyToBoolConverter}”
我使用此代码更改我的UWP应用程序上的按钮颜色
var cd = new ContentDialog();
cd.Content = "Remove file ?";
cd.Title = "Remove file";
cd.PrimaryButtonText = "OK";
cd.SecondaryButtonText = "Cancel";
var bst = new Windows.UI.Xaml.Style(typeof(Button));
bst.Setters.Add(new Setter(Button.BackgroundProperty, Colors.Red));
bst.Setters.Add(new Setter(Button.ForegroundProperty, Colors.White));
cd.PrimaryButtonStyle = bst;
var ress = await cd.ShowAsync();
这是我已经做过的:)但我认为这不是一个好的做法,但aas你也提出了同样的建议,这就是为什么我将此标记为答案。当我在contentDialog中使用Grid时,它在左侧和右侧添加了一个边距,因此内容不完全可见。有什么解决方案吗。PrimaryButtonStyl是什么如果这是真的,则使用e?这不起作用。您是指ContentDialog按钮还是ContentDialog上的任何自定义按钮?默认情况下,我指的是ContentDialog主按钮设置,
Converter={StaticResource StringEmptyToBoolConverter}}"
<ContentDialog.Resources>
<converters:StringEmptyToBoolConverter x:Key="StringEmptyToBoolConverter"/>
<Style TargetType="Button">
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FontSize" Value="13.6"/>
<Setter Property="Width" Value="Auto"/>
</Style>
</ContentDialog.Resources>
<WebView Height="400" Width="500" DefaultBackgroundColor="Transparent" Source="{Binding State.GuideUri}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="RulesWebView"/>
var cd = new ContentDialog();
cd.Content = "Remove file ?";
cd.Title = "Remove file";
cd.PrimaryButtonText = "OK";
cd.SecondaryButtonText = "Cancel";
var bst = new Windows.UI.Xaml.Style(typeof(Button));
bst.Setters.Add(new Setter(Button.BackgroundProperty, Colors.Red));
bst.Setters.Add(new Setter(Button.ForegroundProperty, Colors.White));
cd.PrimaryButtonStyle = bst;
var ress = await cd.ShowAsync();