2026-01-02 17:30:41 +08:00
|
|
|
|
namespace Melskin.Controls;
|
2025-08-20 12:10:13 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// CodeBox 控件用于在用户界面中展示代码片段,支持标题、描述和实际代码内容的自定义。通过该控件,开发者能够方便地嵌入示例代码或文档说明到应用中。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// 本控件扩展了ContentControl类,提供了丰富的属性来定制显示的内容及样式,包括但不限于:标题(Title)、描述(Description)以及代码主体(Code)。此外,还支持使用DataTemplate进一步个性化每个部分的表现形式,使得UI设计更加灵活多样。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public class CodeBox : ContentControl
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于获取或设置CodeBox控件标题文本的依赖属性。此属性允许用户直接设置简单的字符串作为标题内容。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// 通过使用TitleProperty,可以轻松地在XAML或代码中为CodeBox控件指定一个标题。此属性支持数据绑定和动画。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static readonly DependencyProperty TitleProperty =
|
|
|
|
|
|
DependencyProperty.Register(nameof(Title), typeof(string), typeof(CodeBox), new PropertyMetadata(string.Empty));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Title
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (string)GetValue(TitleProperty);
|
|
|
|
|
|
set => SetValue(TitleProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于获取或设置标题内容模板的依赖属性。此属性支持通过DataTemplate来自定义标题部分的视觉呈现。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// TitleTemplateProperty 允许用户使用DataTemplate定义标题的具体布局和样式,从而实现更加灵活的内容展示。
|
|
|
|
|
|
/// 该属性适用于需要对标题文本进行复杂格式化或自定义显示的情况。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static readonly DependencyProperty TitleTemplateProperty =
|
|
|
|
|
|
DependencyProperty.Register(nameof(TitleTemplate), typeof(DataTemplate), typeof(CodeBox), new PropertyMetadata(null));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于获取或设置CodeBox控件标题模板的依赖属性。此属性允许用户自定义标题的显示样式。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// 通过使用TitleTemplate,可以在XAML或代码中为CodeBox控件指定一个数据模板来控制标题的外观。此属性支持复杂的数据绑定和可视化效果,使得标题可以包含更多的UI元素而不只是简单的文本。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public DataTemplate TitleTemplate
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (DataTemplate)GetValue(TitleTemplateProperty);
|
|
|
|
|
|
set => SetValue(TitleTemplateProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly DependencyProperty DescriptionProperty =
|
|
|
|
|
|
DependencyProperty.Register(nameof(Description), typeof(string), typeof(CodeBox), new PropertyMetadata(string.Empty));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
///
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string Description
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (string)GetValue(DescriptionProperty);
|
|
|
|
|
|
set => SetValue(DescriptionProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于获取或设置描述内容模板的依赖属性。此属性支持通过DataTemplate来自定义描述部分的视觉呈现。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// DescriptionTemplateProperty 允许用户使用DataTemplate定义描述信息的具体布局和样式,从而实现更加灵活的内容展示。
|
|
|
|
|
|
/// 该属性适用于需要对描述文本进行复杂格式化或自定义显示的情况。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static readonly DependencyProperty DescriptionTemplateProperty =
|
|
|
|
|
|
DependencyProperty.Register(nameof(DescriptionTemplate), typeof(DataTemplate), typeof(CodeBox), new PropertyMetadata(null));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置用于描述内容的模板。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// 该属性允许用户自定义描述内容的显示样式。通过设置DescriptionTemplate,可以使用DataTemplate来定义描述部分的具体布局和外观。
|
|
|
|
|
|
/// 这对于需要以特定格式展示描述信息的情况非常有用,例如添加图标、调整字体样式或者进行其他视觉上的定制。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public DataTemplate DescriptionTemplate
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (DataTemplate)GetValue(DescriptionTemplateProperty);
|
|
|
|
|
|
set => SetValue(DescriptionTemplateProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置代码框中显示的代码字符串。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// 该属性允许用户指定在CodeBox控件内显示的具体代码内容。通过绑定或直接赋值的方式,可以动态改变显示的代码文本。
|
|
|
|
|
|
/// 使用此属性时,可以通过设置CodeTemplate来自定义代码的展示样式。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public static readonly DependencyProperty CodeProperty =
|
|
|
|
|
|
DependencyProperty.Register(nameof(Code), typeof(string), typeof(CodeBox), new PropertyMetadata(string.Empty));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取或设置代码框中显示的代码字符串。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// 该属性允许用户指定在CodeBox控件内显示的具体代码内容。通过绑定或直接赋值的方式,可以动态改变显示的代码文本。
|
|
|
|
|
|
/// 使用此属性时,可以通过设置CodeTemplate来自定义代码的展示样式。
|
|
|
|
|
|
/// </remarks>
|
|
|
|
|
|
public string Code
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (string)GetValue(CodeProperty);
|
|
|
|
|
|
set => SetValue(CodeProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于定义代码块显示模板的依赖属性。此属性允许用户自定义代码内容的呈现方式。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static readonly DependencyProperty CodeTemplateProperty =
|
|
|
|
|
|
DependencyProperty.Register(nameof(CodeTemplate), typeof(DataTemplate), typeof(CodeBox), new PropertyMetadata(null));
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于定义代码块显示模板的属性。通过设置此属性,用户可以自定义代码内容的显示方式。
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DataTemplate CodeTemplate
|
|
|
|
|
|
{
|
|
|
|
|
|
get => (DataTemplate)GetValue(CodeTemplateProperty);
|
|
|
|
|
|
set => SetValue(CodeTemplateProperty, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
static CodeBox()
|
|
|
|
|
|
{
|
|
|
|
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(CodeBox), new FrameworkPropertyMetadata(typeof(CodeBox)));
|
|
|
|
|
|
}
|
|
|
|
|
|
//public CodeBox()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// SetResourceReference(StyleProperty, typeof(CodeBox));
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|