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>

相关推荐
界面开发小八哥20 分钟前
界面组件DevExpress WPF v24.1 - 增强的可访问性 & UI自动化
ui·wpf·界面开发·界面控件·devexpress
前端组件开发22 分钟前
基于uni-app与图鸟UI的移动应用模板构建研究
java·开发语言·前端·ui·小程序·前端框架·uni-app
weixin_8368695201 小时前
Java中的机器学习模型集成与训练
java·开发语言·机器学习
IT数据小能手1 小时前
Python中爬虫编程的常见问题及解决方案
开发语言·爬虫·python
大卫的纯爱战士1 小时前
c++指针和引用之高难度(二)习题讲解
开发语言·c++
画饼校长2 小时前
【C++ Primer Plus学习记录】函数的基本知识
开发语言·c++·学习·visualstudio·软件工程
烛九_阴3 小时前
【讨论C++继承】
开发语言·c++
凉拌糖醋鱼4 小时前
Python-PDF文件密码破解小工具
开发语言·python·pdf·密码破解
“αβ”5 小时前
c语言的烫烫烫烫烫??
c语言·开发语言·c++
臻一6 小时前
C++编程(五)单例模式 友元
开发语言·c++·设计模式