可以看到,系统除创建了BBSComment.cs外,还创建了一个Themes/Generic.xaml(这个可以理解为web网站开发中的css,不过功能相对css更强大) ? 参考上图,找到Assets标签,选择Project,就能看到BBSComment这个控件了,直接用鼠标按住拖到MainPage.xaml中来即可(爽吧,呵) 刚才提到了Generic.xaml类似传统web 即资源文件不能在设计视图下编辑,要编辑资源,请切换到资源面板 换到资源面板,展开Generic.xaml,会发现刚才定义的二个样式显示于此,每个后面还有一个编辑按钮 ? 完成之后,观察Generic.xaml中的变化 <Border Width="{TemplateBinding Width}" Height="50" Background="Red" BorderBrush 比如同样是刚才的BBSComment控件,我们可以把generic.xaml中style2的定义改为: <Style TargetType="local:BBSComment" x:Name="style2
话框中选中TemplatedControl,名称部分输入“MyFirstControl”,点击“添加”后VisualStudio会自动在项目中添加两个文件:MyFirstControl.cs和Themes/Generic.xaml 2.2 Themes/Generic.xaml <Style TargetType="local:MyFirstControl" > <Setter Property="Template"> 使用Blend打开项目后,在“资源”面板展开Generic.xaml节点,选中MyFirstControl,点击编辑资源: ?
XAML 文件的始终应该作为最终用户界面,不应该当作控件使用(不要试图在其他地方使用时还设置其 Content 属性); 如果你确实希望做控件,请继承自 CustomControl 然后在 /Themes/Generic.xaml 将 <UserControl.Style> 里定义的所有样式全部改到 /Themes/Generic.xaml 文件中。 DefaultStyleKeyProperty.OverrideMetadata(typeof(Foo), new FrameworkPropertyMetadata(typeof(Foo))); } } } /Themes/Generic.xaml
Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.14393.0\Generic\generic.xaml ApplicationPageBackgroundThemeBrush}",在资源名称(ApplicationPageBackgroundThemeBrush)上按"F12",即可导航到存放ThemeResource的generic.xaml
ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Rubyer;component/Themes/<em>Generic.xaml</em>
3.2 合并资源字典 如果一个项目的模板化控件太多,Generic.xaml会异常的复杂,可以将各个控件的资源文件分开存放,再在Generic.xaml中合并它们。
,点击“添加”后VisualStudio会自动创建两个文件:MyHeaderedContentControl.cs和Themes/Generic.xaml。 ? 自定义控件的组成 自定义控件通常由代码和DefaultStyle两部分组成,它们分别位于VisualStudio创建的MyHeaderedContentControl.cs和Themes/Generic.xaml </ControlTemplate> </Setter.Value> </Setter> </Style> 在第一次创建控件后VisualStudio会自动创建Themes/Generic.xaml
这些默认样式在已安装的 Windows 10 SDK 中被提供,比如 SDK 默认安装在 C 盘的时候,控件样式字典 generic.xaml 可以在 C:\Program Files (x86)\Windows
ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Rubyer;component/Themes/<em>Generic.xaml</em>
ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Rubyer;component/Themes/<em>Generic.xaml</em>
public CustomTheme() { this.Source = new Uri( "/Telerik.Windows.Themes.CustomTheme;component/themes/Generic.xaml
Application.Resources> <ResourceDictionary Source="pack://application:,,,/Fluent;Component/Themes/<em>Generic.xaml</em>
ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Rubyer;component/Themes/<em>Generic.xaml</em>
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyControl),newFrameworkPropertyMetadata(typeof(MyControl))) 控件就会通过程序集theme文件夹下的generic.xaml
Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.17763.0\Generic\generic.xaml
:则说明特定主题资源在外部同名,不同后缀的程序集中(例如resentationFramework.Aero)而这个选择由系统主题决定 而最后,如果这些主题都没有找到,那么程序会在自身的themes/generic.xaml
然后新建资源字典 Generic.xaml ,注意名称也是不能自己修改。 在 Generic.xaml 合并字典 <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ms-appx
只是一个很简单的程序,甚至懒得写到Generic.xaml中,直接使用UserControl。
在开发自定义控件时会自动生成一个 Theme/Generic.xaml 文件。 可以在 Theme/ 这个文件夹中为不同的操作系统主题设计不同的控件样式,而找不到相关主题对应的文件时,则会使用 Generic.xaml 文件中的控件样式。
让我们添加一个文本类型的项目到公秤里,命名为generic.xaml。 ? 选择generic.xaml文件并设置为嵌入式资源。