wpf 附加属性 RegisterAttached 内容属性

//

// 摘要:

// 选中时展示的元素

public static readonly DependencyProperty CheckedElementProperty = DependencyProperty.RegisterAttached("CheckedElement", typeof(object), typeof(StatusSwitchElement), new PropertyMetadata((object)null));

//

// 摘要:

// 是否隐藏元素

public static readonly DependencyProperty HideUncheckedElementProperty = DependencyProperty.RegisterAttached("HideUncheckedElement", typeof(bool), typeof(StatusSwitchElement), new PropertyMetadata(ValueBoxes.FalseBox));

public static void SetCheckedElement(DependencyObject element, object value)

{

element.SetValue(CheckedElementProperty, value);

}

public static object GetCheckedElement(DependencyObject element)

{

return element.GetValue(CheckedElementProperty);

}

public static void SetHideUncheckedElement(DependencyObject element, bool value)

{

element.SetValue(HideUncheckedElementProperty, ValueBoxes.BooleanBox(value));

}

public static bool GetHideUncheckedElement(DependencyObject element)

{

return (bool)element.GetValue(HideUncheckedElementProperty);

}

}

用法:

<Style x:Key="DemoInfoSortButtonStyle" BasedOn="{StaticResource ToggleButtonCustom}" TargetType="ToggleButton" x:Shared="False">

<Setter Property="Content">

<Setter.Value>

<Border CornerRadius="4" BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" Height="30" Width="30" >

<Image Stretch="None" Source="pack://application:,,,/Resource/Image/LeftMainContent/SortAscending_gray_16x.png"/>

</Border>

</Setter.Value>

</Setter>

<Setter Property="hc:StatusSwitchElement.CheckedElement">

<Setter.Value>

<Border CornerRadius="4" Height="30" Width="30" BorderThickness="1" BorderBrush="{DynamicResource PrimaryBrush}"/>

</Setter.Value>

</Setter>

</Style>

相关推荐
高级盘丝洞4 小时前
如何通过Powerlink协议读取PLC数据
开发语言·数据库·php
Yang-Never4 小时前
Open GL ES->EGL渲染环境、数据、引擎、线程的创建
android·java·开发语言·kotlin·android studio
unicrom_深圳市由你创科技4 小时前
使用 Vue3 + Nest.js 构建前后端分离项目的完整指南
开发语言·javascript·状态模式
我叫张小白。4 小时前
Vue3 v-model:组件通信的语法糖
开发语言·前端·javascript·vue.js·elementui·前端框架·vue
翻斗花园牛图图-4 小时前
Qt开发——系统相关3(Qt网络编程)
开发语言·qt
Aevget4 小时前
界面控件DevExpress WPF中文教程:Data Grid - 虚拟源限制
hadoop·wpf·界面控件·devexpress·ui开发
kk”5 小时前
C++ AVL树
开发语言·数据结构·c++
繁华似锦respect5 小时前
C++ 设计模式之观察者模式详细介绍
linux·开发语言·c++·windows·观察者模式·设计模式·visual studio
froginwe115 小时前
CSS Text(文本)详解
开发语言
繁华似锦respect5 小时前
C++ 自定义 String 类
服务器·开发语言·c++·哈希算法·visual studio