2025-08-12 23:08:54 +08:00
|
|
|
|
|
2025-12-23 21:35:54 +08:00
|
|
|
|
using System.Windows.Controls.Primitives;
|
2026-01-02 17:30:30 +08:00
|
|
|
|
using VariaStudio.Controls;
|
2025-12-23 21:35:54 +08:00
|
|
|
|
|
2026-01-02 17:30:30 +08:00
|
|
|
|
namespace VariaStudio.Assists;
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 提供各种控件的附加属性帮助类。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class ControlAssist
|
|
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 按钮变体附加属性的获取方法。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static Variant GetVariant(DependencyObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (Variant)obj.GetValue(VariantProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 按钮变体附加属性的设置方法。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj"></param>
|
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
public static void SetMyProperty(DependencyObject obj, Variant value)
|
|
|
|
|
|
{
|
|
|
|
|
|
obj.SetValue(VariantProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 按钮变体附加属性
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly DependencyProperty VariantProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("Variant", typeof(Variant), typeof(ControlAssist), new PropertyMetadata(Variant.Default));
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 定义一个附加属性 IsFlowLayout (或者叫 UseWrapPanel)
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty IsFlowLayoutProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"IsFlowLayout",
|
|
|
|
|
|
typeof(bool),
|
|
|
|
|
|
typeof(ControlAssist),
|
|
|
|
|
|
new PropertyMetadata(false));
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 流式布局
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="element"></param>
|
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
|
public static void SetIsFlowLayout(DependencyObject element, bool value)
|
2025-08-20 12:10:13 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
element.SetValue(IsFlowLayoutProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 流式布局附加属性的获取方法。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="element"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(ListBox))]
|
|
|
|
|
|
public static bool GetIsFlowLayout(DependencyObject element)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (bool)element.GetValue(IsFlowLayoutProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定对象的外观类型。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">要获取其外观类型的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回指定对象的AppearanceType枚举值,表示其外观类型。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(Button))]
|
|
|
|
|
|
public static AppearanceType GetAppearanceType(DependencyObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (AppearanceType)obj.GetValue(AppearanceTypeProperty);
|
2025-08-20 12:10:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置指定对象的外观类型。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置其外观类型的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">AppearanceType枚举值,表示要设置的外观类型。</param>
|
|
|
|
|
|
public static void SetAppearanceType(DependencyObject obj, AppearanceType value)
|
2025-08-20 12:10:13 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(AppearanceTypeProperty, value);
|
2025-08-20 12:10:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 代表按钮控件的外观类型依赖属性。通过此属性,可以设置或获取按钮的视觉样式。
|
|
|
|
|
|
/// 支持的样式包括Primary、Info、Success、Warning和Error,分别对应不同的视觉效果。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty AppearanceTypeProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("AppearanceType", typeof(AppearanceType), typeof(ControlAssist), new PropertyMetadata(AppearanceType.None));
|
2025-08-20 12:10:13 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取指定对象的图标。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取其图标的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回指定对象的IconElement,表示其图标。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(Button))]
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(Menu))]
|
|
|
|
|
|
public static IconElement GetIcon(DependencyObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (IconElement)obj.GetValue(IconProperty);
|
|
|
|
|
|
}
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 为指定对象设置图标。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要为其设置图标的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">要设置的IconElement值。</param>
|
|
|
|
|
|
public static void SetIcon(DependencyObject obj, IconElement value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(IconProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 代表按钮控件的图标依赖属性。通过此属性,可以设置或获取按钮上显示的图标。
|
|
|
|
|
|
/// 支持使用IconElement来指定具体的图标样式。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty IconProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("Icon", typeof(IconElement), typeof(ControlAssist), new PropertyMetadata(null));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定对象的图标放置位置。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">要获取其图标放置位置的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回指定对象的Dock枚举值,表示图标的放置位置。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(Button))]
|
|
|
|
|
|
public static Dock GetIconPlacement(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (Dock)obj.GetValue(IconPlacementProperty);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置指定对象的图标放置位置。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">要设置其图标放置位置的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">图标放置位置的值,使用Dock枚举表示。</param>
|
|
|
|
|
|
public static void SetIconPlacement(DependencyObject obj, Dock value)
|
|
|
|
|
|
{
|
|
|
|
|
|
obj.SetValue(IconPlacementProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 代表按钮控件的图标位置依赖属性。通过此属性,可以设置或获取按钮上图标的放置位置。
|
|
|
|
|
|
/// 支持使用Dock枚举中的值来指定图标相对于按钮文本的位置,例如左对齐、右对齐等。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly DependencyProperty IconPlacementProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("IconPlacement", typeof(Dock), typeof(ControlAssist), new PropertyMetadata(Dock.Left));
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 代表按钮控件是否正在运行的依赖属性。通过此属性,可以设置或获取按钮的运行状态。
|
|
|
|
|
|
/// 此属性通常用于指示按钮关联的操作是否正在进行中,例如数据加载或处理过程。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty IsRunningProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("IsRunning", typeof(bool), typeof(ControlAssist), new PropertyMetadata(false));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定对象的IsRunning状态。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">要获取其IsRunning状态的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回一个布尔值,表示指定对象是否正在运行。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(Button))]
|
|
|
|
|
|
public static bool GetIsRunning(DependencyObject obj) => (bool)obj.GetValue(IsRunningProperty);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置指定对象的运行状态。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">要设置其运行状态的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">布尔值,表示对象是否处于运行状态。</param>
|
|
|
|
|
|
public static void SetIsRunning(DependencyObject obj, bool value) => obj.SetValue(IsRunningProperty, value);
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 附加属性,用于为UI元素指定一个字符串形式的标识符(锚点名称)。此属性允许开发者将特定的标识字符串与UI元素关联起来,
|
|
|
|
|
|
/// 从而在WPF应用程序中实现基于内容滚动位置自动更新当前高亮显示的锚点列表项等功能。通过设置该属性,可以方便地进行用户界面中的快速导航。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly DependencyProperty AnchorHeaderTextProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"AnchorHeaderText",
|
|
|
|
|
|
typeof(string),
|
|
|
|
|
|
typeof(ControlAssist),
|
|
|
|
|
|
new PropertyMetadata(null));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定依赖对象的Header属性值。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">要获取Header属性值的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回指定依赖对象的Header属性值,如果未设置则返回null。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(Anchor))]
|
|
|
|
|
|
public static string GetAnchorHeaderText(DependencyObject obj)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (string)obj.GetValue(AnchorHeaderTextProperty);
|
|
|
|
|
|
}
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 为指定依赖对象设置Header属性值。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="obj">要设置Header属性的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">要设置的Header属性值,类型为字符串。</param>
|
|
|
|
|
|
public static void SetAnchorHeaderText(DependencyObject obj, string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
obj.SetValue(AnchorHeaderTextProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取指定对象的Orientation属性值。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取Orientation属性的对象。</param>
|
|
|
|
|
|
/// <returns>返回对象的Orientation属性值,可以是Horizontal或Vertical。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(ListBox))]
|
|
|
|
|
|
public static Orientation GetOrientation(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (Orientation)obj.GetValue(OrientationProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置指定对象的Orientation属性。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置Orientation属性的对象。</param>
|
|
|
|
|
|
/// <param name="value">要设置的Orientation值,可以是Horizontal或Vertical。</param>
|
|
|
|
|
|
public static void SetOrientation(DependencyObject obj, Orientation value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(OrientationProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 表示选择器控件的方向属性,可以用来设置或获取指定依赖对象的Orientation属性值。该属性支持两种方向:Horizontal(水平)和Vertical(垂直),默认值为Vertical。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty OrientationProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("Orientation", typeof(Orientation), typeof(ControlAssist), new PropertyMetadata(Orientation.Vertical));
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取指定依赖对象的SynchronizedScroll属性值。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取SynchronizedScroll属性值的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回与指定依赖对象关联的ScrollViewer。如果未设置,则返回null。</returns>
|
|
|
|
|
|
public static ScrollViewer GetSynchronizedScroll(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (ScrollViewer)obj.GetValue(SynchronizedScrollProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置指定依赖对象的SynchronizedScroll属性值。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置SynchronizedScroll属性的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">要设置的ScrollViewer值,用于同步滚动位置。</param>
|
|
|
|
|
|
public static void SetSynchronizedScroll(DependencyObject obj, ScrollViewer value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(SynchronizedScrollProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// SynchronizedScrollProperty 是一个依赖属性,用于在多个 ScrollViewer 控件之间同步滚动位置。通过此属性,可以设置或获取与特定依赖对象关联的 ScrollViewer 实例,从而实现当一个 ScrollViewer 的滚动位置发生变化时,其他关联的 ScrollViewer 也能自动调整其滚动位置以保持一致。
|
|
|
|
|
|
/// 主要用于在 WPF 应用程序中实现多 ScrollViewer 之间的滚动同步功能,特别适用于需要同时滚动显示不同内容但保持视觉一致性的场景。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty SynchronizedScrollProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("SynchronizedScroll",
|
|
|
|
|
|
typeof(ScrollViewer), typeof(ControlAssist),
|
|
|
|
|
|
new PropertyMetadata(null, OnSynchronizedScrollChanged));
|
|
|
|
|
|
|
|
|
|
|
|
private static void OnSynchronizedScrollChanged(DependencyObject d,
|
|
|
|
|
|
DependencyPropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (d is not ScrollViewer scroll)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//从无到有
|
|
|
|
|
|
if (e.OldValue == null && e.NewValue != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
scroll.ScrollChanged += SynchronizeScrollViewer;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void SynchronizeScrollViewer(object sender, ScrollChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
var senderScroll = sender as ScrollViewer;
|
|
|
|
|
|
if (senderScroll == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取要被驱动的ScrollViewer
|
|
|
|
|
|
var targetScroll = GetSynchronizedScroll(senderScroll);
|
|
|
|
|
|
targetScroll.ScrollToHorizontalOffset(senderScroll.HorizontalOffset);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region Toggle
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取指定依赖对象的开关处于关闭状态时显示的文本。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取关闭状态文本的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回一个字符串,表示开关处于关闭状态时显示的文本。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(ToggleButton))]
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetOffText(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (string)obj.GetValue(OffTextProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置开关控件在关闭状态时显示的文本。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">依赖对象,通常为开关控件实例。</param>
|
|
|
|
|
|
/// <param name="value">要设置的文本值。</param>
|
|
|
|
|
|
public static void SetOffText(DependencyObject obj, string value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(OffTextProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 21:35:54 +08:00
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 用于获取或设置开关处于关闭状态时显示的文本。
|
|
|
|
|
|
/// 默认值为"关"。此依赖属性支持动画、样式和数据绑定等功能。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty OffTextProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("OffText", typeof(string), typeof(ControlAssist), new PropertyMetadata("关"));
|
|
|
|
|
|
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取指定依赖对象的开关处于开启状态时显示的文本。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取开启状态文本的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回一个字符串,表示开关处于开启状态时显示的文本。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(ToggleButton))]
|
|
|
|
|
|
public static string GetOnText(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (string)obj.GetValue(OnTextProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置指定依赖对象的开关处于开启状态时显示的文本。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置开启状态文本的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">要设置的文本值。</param>
|
|
|
|
|
|
public static void SetOnText(DependencyObject obj, string value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(OnTextProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 21:35:54 +08:00
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 用于获取或设置开关处于开启状态时显示的文本。
|
|
|
|
|
|
/// 默认值为"开"。此依赖属性支持动画、样式和数据绑定等功能。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty OnTextProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("OnText", typeof(string), typeof(ControlAssist), new PropertyMetadata("开"));
|
|
|
|
|
|
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取指定依赖对象的开关是否显示文本的状态。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取显示文本状态的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回一个布尔值,表示开关是否显示文本。如果为true,则显示文本;如果为false,则不显示文本。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(ToggleButton))]
|
|
|
|
|
|
public static bool GetShowText(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (bool)obj.GetValue(ShowTextProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置指定依赖对象的开关控件是否显示文本。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置显示文本状态的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">布尔值,表示是否显示文本。如果为true,则显示文本;如果为false,则不显示文本。</param>
|
|
|
|
|
|
public static void SetShowText(DependencyObject obj, bool value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(ShowTextProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 用于获取或设置是否显示开关状态文本。
|
|
|
|
|
|
/// 默认值为false。此依赖属性支持动画、样式和数据绑定等功能。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty ShowTextProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("ShowText", typeof(bool), typeof(ControlAssist), new PropertyMetadata(false));
|
|
|
|
|
|
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取指定依赖对象的开关处于关闭状态时的内容。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取关闭状态内容的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回一个对象,表示开关处于关闭状态时显示的内容。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(ToggleButton))]
|
|
|
|
|
|
public static object GetOffContent(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (object)obj.GetValue(OffContentProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置指定依赖对象的开关处于关闭状态时显示的内容。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置关闭状态内容的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">要设置为关闭状态时显示的内容。</param>
|
|
|
|
|
|
public static void SetOffContent(DependencyObject obj, object value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(OffContentProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 21:35:54 +08:00
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 用于获取或设置开关处于关闭状态时显示的内容。
|
|
|
|
|
|
/// 默认值为null。此依赖属性支持动画、样式和数据绑定等功能。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty OffContentProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("OffContent", typeof(object), typeof(ControlAssist), new PropertyMetadata(null));
|
|
|
|
|
|
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取指定依赖对象的开关处于开启状态时的内容。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取开启状态内容的依赖对象。</param>
|
|
|
|
|
|
/// <returns>返回一个对象,表示开关处于开启状态时的内容。</returns>
|
|
|
|
|
|
[AttachedPropertyBrowsableForType(typeof(ToggleButton))]
|
|
|
|
|
|
public static object GetOnContent(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (object)obj.GetValue(OnContentProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置指定依赖对象的开关处于开启状态时显示的内容。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置开启状态内容的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">要设置为开启状态时显示的内容,可以是任何类型的对象,如字符串或UI元素。</param>
|
|
|
|
|
|
public static void SetOnContent(DependencyObject obj, object value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(OnContentProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-23 21:35:54 +08:00
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 用于获取或设置开关处于开启状态时显示的内容。
|
|
|
|
|
|
/// 默认值为null。此依赖属性支持动画、样式和数据绑定等功能。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty OnContentProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("OnContent", typeof(object), typeof(ControlAssist), new PropertyMetadata(null));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Border
|
2025-08-12 23:08:54 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取与指定依赖对象关联的几何图形。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取其几何图形属性的依赖对象。</param>
|
|
|
|
|
|
/// <returns>与指定依赖对象关联的几何图形。</returns>
|
|
|
|
|
|
public static Geometry GetGeometry(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (Geometry)obj.GetValue(GeometryProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置与指定依赖对象关联的几何图形。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要设置其几何图形属性的依赖对象。</param>
|
|
|
|
|
|
/// <param name="value">要与此依赖对象关联的新几何图形值。</param>
|
|
|
|
|
|
public static void SetGeometry(DependencyObject obj, Geometry value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(GeometryProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 代表附加到控件的几何图形属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取几何图形。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly DependencyProperty GeometryProperty =
|
|
|
|
|
|
DependencyProperty.RegisterAttached("Geometry",
|
|
|
|
|
|
typeof(Geometry), typeof(ControlAssist));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 代表附加到控件的圆角半径属性。此依赖属性允许在WPF应用程序中为任意控件设置和获取圆角半径,影响控件的测量和渲染。
|
2025-08-20 12:10:13 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached(
|
|
|
|
|
|
"CornerRadius",
|
|
|
|
|
|
typeof(CornerRadius),
|
2025-08-12 23:08:54 +08:00
|
|
|
|
typeof(ControlAssist),
|
|
|
|
|
|
new FrameworkPropertyMetadata(
|
2025-12-23 21:35:54 +08:00
|
|
|
|
new CornerRadius(4),
|
|
|
|
|
|
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender
|
2025-08-12 23:08:54 +08:00
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 获取与指定依赖对象关联的圆角半径。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// <param name="obj">要获取其圆角半径属性的依赖对象。</param>
|
|
|
|
|
|
/// <returns>与指定依赖对象关联的圆角半径。</returns>
|
|
|
|
|
|
[Category("NeuAssists")]
|
|
|
|
|
|
public static CornerRadius GetCornerRadius(DependencyObject obj)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
return (CornerRadius)obj.GetValue(CornerRadiusProperty);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
/// 设置与指定依赖对象关联的圆角半径。
|
2025-08-12 23:08:54 +08:00
|
|
|
|
/// </summary>
|
2025-12-23 21:35:54 +08:00
|
|
|
|
public static void SetCornerRadius(DependencyObject obj, CornerRadius value)
|
2025-08-12 23:08:54 +08:00
|
|
|
|
{
|
2025-12-23 21:35:54 +08:00
|
|
|
|
obj.SetValue(CornerRadiusProperty, value);
|
2025-08-12 23:08:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2025-12-23 21:35:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
2025-08-20 12:10:13 +08:00
|
|
|
|
}
|