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>

相关推荐
咕噜咕噜啦啦3 分钟前
Java速通(应用程序)
java·开发语言
我是人机不吃鸭梨11 分钟前
Flutter AI 集成革命(2025版):从 Gemini 模型到智能表单验证器的终极方案
开发语言·javascript·人工智能·flutter·microsoft·架构
沐知全栈开发11 分钟前
服务定位器模式
开发语言
期待のcode15 分钟前
Java Object 类
java·开发语言
Wang's Blog21 分钟前
Lua: 协程编程详解之从基础到多任务处理与应用实战
开发语言·lua
笙枫26 分钟前
LangGraph Agent 架构基础:从概念到第一个可运行的Agent
开发语言·架构·php
csbysj202044 分钟前
DOM 验证
开发语言
superman超哥1 小时前
Rust 表达式与语句的区别:函数式思维与控制流设计
开发语言·后端·rust·rust表达式·rust语句·函数式思维·控制流设计
趁月色小酌***1 小时前
JAVA 知识点总结5
java·开发语言·python
05大叔1 小时前
SpringMVCDay01
java·开发语言