控件依赖属性:
#region SelectionText
internal static readonly DependencyPropertyKey SelectionTextPropertyKey = DependencyProperty.RegisterReadOnly(
"SelectionText", typeof(string),
typeof(QuJiaoRichTextBox), new PropertyMetadata(string.Empty)
);
public static readonly DependencyProperty SelectionTextProperty = SelectionTextPropertyKey.DependencyProperty;
/// <summary>
/// 当前选择文本(外部只读)
/// </summary>
public string SelectionText
{
get => (string)GetValue(SelectionTextPropertyKey.DependencyProperty);
internal set => SetValue(SelectionTextPropertyKey, value);
}
#endregion
xaml调用时绑定:
SelectionText="{Binding Path=模型的绑定属性名称,ElementName=SelectionText}"
本文详细解析了控件依赖属性的实现方式,通过WPF框架中的QuJiaoRichTextBox控件为例,展示了如何定义和使用SelectionText依赖属性,实现对外部只读的选择文本功能。
2497

被折叠的 条评论
为什么被折叠?



