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>

相关推荐
LDR00613 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
雪碧聊技术13 天前
Tree.js是什么?一文讲透
开发语言·javascript·ecmascript
码云数智-园园13 天前
C++20 Modules 模块详解
java·开发语言·spring
swordbob13 天前
NIO的channel中什么是 fd(File Descriptor,文件描述符)
java·开发语言·nio
源分享13 天前
Java线程同步的多种实现方法(非常详细)
java·开发语言·jvm
Luminous.13 天前
C语言--day30
c语言·开发语言
何以解忧,唯有..13 天前
Go语言循环语句详解:for、range与循环控制
开发语言·算法·golang
謓泽13 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
云水一下13 天前
从零开始学 PHP 系列(一):PHP 的前世今生与开发环境搭建
开发语言·php
飞天狗11113 天前
零基础JavaWeb入门——第五课第二小节:九大内置对象 · 第2个:response(响应对象)
java·开发语言