63 lines
2.7 KiB
C#
63 lines
2.7 KiB
C#
|
|
namespace NeoUI.Assists;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// SelectorAssist 类提供了附加属性,用于增强选择器控件(如 ComboBox, ListBox 等)的功能。通过这些附加属性,可以设置选择器的方向和占位符文本。
|
|||
|
|
/// </summary>
|
|||
|
|
public class SelectorAssist
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取指定对象的Orientation属性值。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="obj">要获取Orientation属性的对象。</param>
|
|||
|
|
/// <returns>返回对象的Orientation属性值,可以是Horizontal或Vertical。</returns>
|
|||
|
|
public static Orientation GetOrientation(DependencyObject obj)
|
|||
|
|
{
|
|||
|
|
return (Orientation)obj.GetValue(OrientationProperty);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置指定对象的Orientation属性。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="obj">要设置Orientation属性的对象。</param>
|
|||
|
|
/// <param name="value">要设置的Orientation值,可以是Horizontal或Vertical。</param>
|
|||
|
|
public static void SetOrientation(DependencyObject obj, Orientation value)
|
|||
|
|
{
|
|||
|
|
obj.SetValue(OrientationProperty, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 表示选择器控件的方向属性,可以用来设置或获取指定依赖对象的Orientation属性值。该属性支持两种方向:Horizontal(水平)和Vertical(垂直),默认值为Vertical。
|
|||
|
|
/// </summary>
|
|||
|
|
public static readonly DependencyProperty OrientationProperty =
|
|||
|
|
DependencyProperty.RegisterAttached("Orientation", typeof(Orientation), typeof(SelectorAssist), new PropertyMetadata(Orientation.Vertical));
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取指定对象的占位符文本。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="obj">要获取占位符文本的对象。</param>
|
|||
|
|
/// <returns>返回对象的占位符文本,如果未设置则返回默认值。</returns>
|
|||
|
|
public static string GetPlaceholder(DependencyObject obj)
|
|||
|
|
{
|
|||
|
|
return (string)obj.GetValue(PlaceholderProperty);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 设置指定对象的占位符文本。
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="obj">要设置占位符文本的对象。</param>
|
|||
|
|
/// <param name="value">要设置的占位符文本值。</param>
|
|||
|
|
public static void SetPlaceholder(DependencyObject obj, string value)
|
|||
|
|
{
|
|||
|
|
obj.SetValue(PlaceholderProperty, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 表示选择器控件的占位符文本属性,可以用来设置或获取指定依赖对象的占位符文本。默认值为"请选择...",用于在选择器没有选中项时显示提示信息。
|
|||
|
|
/// </summary>
|
|||
|
|
public static readonly DependencyProperty PlaceholderProperty =
|
|||
|
|
DependencyProperty.RegisterAttached("Placeholder", typeof(string), typeof(SelectorAssist), new PropertyMetadata("请选择..."));
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|