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>

相关推荐
小灰灰搞电子5 小时前
Rust+Slint 实现动态消息提示框源码分享
开发语言·后端·rust
传奇开心果编程7 小时前
【Rust入门知识点学与练】第21课:Trait 进阶 Advanced Traits
开发语言·学习·rust
新时代牛马7 小时前
字符设备驱动完整篇:从 cdev_add、file_operations 到chrdev_open 与排障
开发语言·python
swordbob7 小时前
ReentrantLock 与 AQS 完整学习手册
java·开发语言
白山编程大哥8 小时前
Java OutputStreamWriter 详解:从字符到字节的桥梁
java·开发语言·python
shmily麻瓜小菜鸡9 小时前
JavaScript / TypeScript 易踩坑知识点 —— 异步编程类
开发语言·javascript·typescript
七夜zippoe9 小时前
为什么 2026 年每个 Java 团队都该懂 AI Agent
java·开发语言·人工智能
znnnk9 小时前
【Python】GUI 开发从入门到实战(三):PyQt/PySide 进阶之路
开发语言·python·pyqt
Despacito100610 小时前
Java后端性能探查工具速查表
java·开发语言
晊晌_h10 小时前
嵌入式从0到精通——Linux C|TCP 并发服务器实现方案详解
服务器·开发语言·tcp/ip