wpf generic.xmal在类库中使用

本文介绍了如何在WPF类库中创建并使用Generic.xaml来定义自定义控件的默认主题。步骤包括在类库中扩展类并设置DefaultStyleKeyProperty,创建Themes目录,以及在该目录下创建Generic.xaml文件。完成这些步骤后,主窗口就能正常使用自定义控件的主题了。
摘要由CSDN通过智能技术生成

创建自定义控件时会有默认主题generic

使用方法:

1、类库中创建扩展类,加上 DefaultStyleKeyProperty.OverrideMetadata

 public class SearchTextBox : TextBox
    {
        static SearchTextBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(SearchTextBox), new FrameworkPropertyMetadata(typeof(SearchTextBox)));
         }

        public SearchTextBox()
        {
        }
//其它扩展功能....

    }

2、类库中创建Themes目录

3、类库中创建Generic.xaml文件

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ShoppingGuide.Controls">

   <Style TargetType="{x:Type local:SearchTextBox}">
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="{StaticResource 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值