C# 为什么赢了';我的定制现代UI风格不适用吗?
好的,所以我对GUI开发略知一二,而且我对Windows8(现代UI)还是个新手 如果可能的话,我也希望使用C#(无XAML)来实现这一点 风格 我想做的是创建一个样式,我可以应用到其他地方创建的按钮C# 为什么赢了';我的定制现代UI风格不适用吗?,c#,windows-8,styles,setter,modern-ui,C#,Windows 8,Styles,Setter,Modern Ui,好的,所以我对GUI开发略知一二,而且我对Windows8(现代UI)还是个新手 如果可能的话,我也希望使用C#(无XAML)来实现这一点 风格 我想做的是创建一个样式,我可以应用到其他地方创建的按钮 public static Style firstButtonStyle() { firstButton = new Style(typeof(Button)); ControlTemplate btnControl = new ControlTem
public static Style firstButtonStyle()
{
firstButton = new Style(typeof(Button));
ControlTemplate btnControl = new ControlTemplate();
//firstButton.Setters.Add(new Setter(Button.TemplateProperty, btnControl));
firstButton.Setters.Add(new Setter(Button.BackgroundProperty, new SolidColorBrush(Windows.UI.Colors.Blue)));
firstButton.Setters.Add(new Setter(Button.IsPointerOverProperty, new SolidColorBrush(Windows.UI.Colors.PaleGreen)));
firstButton.Setters.Add(new Setter(Button.IsPressedProperty, Windows.UI.Colors.Beige));
firstButton.Setters.Add(new Setter(Button.ForegroundProperty, Windows.UI.Colors.Red));
return firstButton;
}
应用
这是创建按钮和应用样式的位置
private Button enterButtonCreation(string text)
{
Button enterButton = new Button();
enterButton.Content = text;
enterButton.Margin = new Thickness(200, 80, 20, 0);
Style firstButtonStyl = WikierStyle.firstButtonStyle();
enterButton.Style = firstButtonStyl;
enterButton.Background = new SolidColorBrush(Windows.UI.Colors.Silver);
return enterButton;
}
我可以使用.background更改背景,但在使用.BackgroundProperty时,似乎什么也没有发生。首先,我建议您尝试在xaml文件中执行所有样式工作,就像在xaml页面中尝试声明custum样式一样。如果您只想在SpecificularPage中使用custumstyle,那么您的页面只能这样定义它。您可以在任何按钮上应用此样式
<Page
x:Class="Appgridcheck.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Appgridcheck"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<Style TargetType="Button" x:Name="CustomStyle" >
<Setter Property="Background" Value="White" />
</Style>
</Page.Resources>
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Style="{StaticResource CustomStyle}" />
</Grid>
其次,如果您想定义可以在整个应用程序中使用的全局custumStyle(在所有页面上都是这样),请在app.xaml中定义此样式,如下所示
<Application
x:Class="Appgridcheck.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Appgridcheck">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="Button" x:Name="gllobalCustomstyle" >
<Setter Property="Background" Value="Black" />
</Style>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
现在,您可以在任何页面上使用此样式。希望这会有所帮助。但是如果我们从字典中获得我们的要求,我们不知道我们的应用程序中有多少按钮。那么,如何设计一个可以在按钮中动态重用并相应改变其大小的模板呢。请给我一些建议