目录
2.8.2 AdornedElementPlaceholder
2.8 其他FrameworkElement的派生
2.8.1 AccessText
用下划线来指定用作访问键的字符。
如果内容包含多个下划线字符,则只会将第一个下划线字符转换为, AccessKey 其他下划线将显示为普通文本。 如果要转换为访问键的下划线不是第一个下划线,请在要转换的下划线前面使用两个连续的下划线。 例如,以下代码包含一个访问键,并显示为 _Hello W orld:
<AccessText>__Hello_World</AccessText>
由于 H 前面的下划线为 double,因此 W key 注册为访问键。
若要 AccessText 在控件样式中用作内容宿主,请 RecognizesAccessKey 在中设置 ContentPresenter ,如以下示例所示:
<ContentPresenter RecognizesAccessKey="True"/>
public class AccessText : FrameworkElement, IAddChild
{
public static readonly System.Windows.DependencyProperty BackgroundProperty;
public static readonly System.Windows.DependencyProperty BaselineOffsetProperty;
public static readonly System.Windows.DependencyProperty FontFamilyProperty;
public static readonly System.Windows.DependencyProperty FontSizeProperty;
public static readonly System.Windows.DependencyProperty FontStretchProperty;
public static readonly System.Windows.DependencyProperty FontStyleProperty;
public static readonly System.Windows.DependencyProperty FontWeightProperty;
public static readonly System.Windows.DependencyProperty ForegroundProperty;
public static readonly System.Windows.DependencyProperty LineHeightProperty;
public static readonly System.Windows.DependencyProperty LineStackingStrategyProperty;
public static readonly System.Windows.DependencyProperty TextAlignmentProperty;
public static readonly System.Windows.DependencyProperty TextDecorationsProperty;
public static readonly System.Windows.DependencyProperty TextEffectsProperty;
public static readonly System.Windows.DependencyProperty TextProperty;
public static readonly System.Windows.DependencyProperty TextTrimmingProperty;
public static readonly System.Windows.DependencyProperty TextWrappingProperty;
//用于以只读方式访问第一个下划线字符后面的字符。
public char AccessKey { get; }
//获取或设置填充内容区域的 Brush。
public System.Windows.Media.Brush Background { get; set; }
//获取或设置一个值,该值调整文本在 AccessText 元素中的基线偏移位置。
public double BaselineOffset { get; set; }
//获取或设置要用于 AccessText 元素的字体系列。
public System.Windows.Media.FontFamily FontFamily { get; set; }
//获取或设置要用于 AccessText 元素的字体大小。
public double FontSize { get; set; }
//获取或设置一个 FontStretch 属性,该属性从 FontFamily 中选择一个正常、压缩或扩展的字体。
public System.Windows.FontStretch FontStretch { get; set; }
//获取或设置要用于 AccessText 元素的字体样式。
public System.Windows.FontStyle FontStyle { get; set; }
//获取或设置要用于 AccessText 元素的字体粗细。
public System.Windows.FontWeight FontWeight { get; set; }
//获取或设置用于绘制元素的文本内容的 Brush。
public System.Windows.Media.Brush Foreground { get; set; }
//获取或设置每个行框的高度。
public double LineHeight { get; set; }
//获取或设置如何强制应用 LineHeight 属性。
public System.Windows.LineStackingStrategy LineStackingStrategy { get; set; }
//获取一个循环访问该 AccessText 元素的逻辑子元素的枚举数。
protected internal override System.Collections.IEnumerator LogicalChildren { get; }
//获取或设置 AccessText 元素所显示的文本。
public string Text { get; set; }
//获取或设置内容的水平对齐方式。
public System.Windows.TextAlignment TextAlignment { get; set; }
//获取或设置添加到 AccessText 元素的文本的修饰。
public System.Windows.TextDecorationCollection TextDecorations { get; set; }
//获取或设置添加到 AccessText 元素的文本的效果。
public System.Windows.Media.TextEffectCollection TextEffects { get; set; }
//获取或设置在 AccessText 元素的文本内容溢出行框时应如何裁剪这些内容。
public System.Windows.TextTrimming TextTrimming { get; set; }
//获取或设置当 AccessText 元素的文本内容溢出行框时是否换行。
public System.Windows.TextWrapping TextWrapping { get; set; }
//获取可见子元素的数量。
protected override int VisualChildrenCount { get; }
//排列 AccessText 对象的内容并调整其大小。
protected override sealed System.Windows.Size ArrangeOverride(System.Windows.Size arrangeSize);
//获取可见子元素的索引。
protected override System.Windows.Media.Visual GetVisualChild(int index);
//重新测量控件。
protected override sealed System.Windows.Size MeasureOverride(System.Windows.Size constraint);
//有关此成员的说明,请参见 AddChild(Object)。
void IAddChild.AddChild(object value);
//有关此成员的说明,请参见 AddText(String)。
void IAddChild.AddText(string text);
}
2.8.2 AdornedElementPlaceholder
表示 ControlTemplate 中使用的元素,该元素用于指定修饰控件相对于 ControlTemplate 中的其他元素所放置的位置。
仅当你要创建一个用作 ControlTemplate 自定义验证的, ErrorTemplate 以便在用户输入无效时提供可视反馈时,才使用此类。

例如,当输入无效时,您可能希望在文本框旁显示一个红色感叹号,如下图所示。
XAML 对象元素用法
<AdornedElementPlaceholder/>
public class AdornedElementPlaceholder : FrameworkElement, IAddChild
{
//获取此 UIElement 对象为其保留空间的 AdornedElementPlaceholder。
public System.Windows.UIElement AdornedElement { get; }
//获取或设置此 AdornedElementPlaceholder 对象的单一子对象。
public virtual System.Windows.UIElement Child { get; set; }
//获取 AdornedElementPlaceholder 对象的逻辑子元素的枚举器。
protected internal override System.Collections.IEnumerator LogicalChildren { get; }
//获取可见子对象的数目。
protected override int VisualChildrenCount { get; }
//定位第一个可见子对象并返回此 AdornedElementPlaceholder 对象所要求的布局大小。
protected override System.Windows.Size ArrangeOverride(System.Windows.Size arrangeBounds);
//检索位于指定索引处的 Visual 子对象。
protected override System.Windows.Media.Visual GetVisualChild(int index);
//确定 AdornedElementPlaceholder 对象的大小。
protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint);
//引发 IsInitialized 事件。 当在内部将 IsInitialized 设置为 true 时,将调用此方法。
protected override void OnInitialized(EventArgs e);
//此类型或成员支持 Windows Presentation Foundation (WPF) 基础结构,并且不应在代码中直接使用。
void IAddChild.AddChild(object value);
//此类型或成员支持 Windows Presentation Foundation (WPF) 基础结构,并且不应在代码中直接使用。
void IAddChild.AddText(string text);
}
2.8.3 ColumnDefinition
定义将应用于 Grid 元素的特定于列的属性。
ColumnDefinition 使用其自己的特殊结构 a GridLength 来描述其宽度特征。 GridLength 允许 ColumnDefinition 支持可用空间的变量分布。
public class ColumnDefinition : DefinitionBase
{
public static readonly System.Windows.DependencyProperty MaxWidthProperty;
public static readonly System.Windows.DependencyProperty MinWidthProperty;
public static readonly System.Windows.DependencyProperty WidthProperty;
//获取一个值,该值表示实际计算所得的 ColumnDefinition 宽度。
public double ActualWidth { get; }
//获取或设置一个值,该值表示 ColumnDefinition 的最大宽度。
public double MaxWidth { get; set; }
//获取或设置一个值,该值表示 ColumnDefinition 的最小宽度。
public double MinWidth { get; set; }
//获取一个值,该值表示此 ColumnDefinition 的偏移量值。
public double Offset { get; }
//获取 ColumnDefinition 元素的计算所得宽度,或设置由 ColumnDefinition 定义的列的 GridLength 值。
public System.Windows.GridLength Width { get; set; }
}
public abstract class DefinitionBase : FrameworkContentElement
{
public static readonly System.Windows.DependencyProperty SharedSizeGroupProperty;
//获取或设置一个值,该值将 ColumnDefinition 或 RowDefinition 标识为已定义的共享调整大小属性的组的成员。
public string SharedSizeGroup { get; set; }
}
2.8.4 ContentPresenter
显示 ContentControl 的内容。
通常使用的 ContentPresenter 中的 ControlTemplate ContentControl 来指定要添加内容的位置。 每个 ContentControl 类型的 ContentPresenter 默认值均为 ControlTemplate 。
当 ContentPresenter 对象位于的中时, ControlTemplate ContentControl Content 、 ContentTemplate 和属性将 ContentTemplateSelector 从相同名称的属性中获取其值 ContentControl 。 可以让 ContentPresenter 属性通过设置 ContentSource 属性或绑定到模板父级的其他属性来获取这些属性的值。
ContentPresenter使用以下逻辑显示 Content :
- 如果 ContentTemplate 设置了的属性 ContentPresenter ,则会将其 ContentPresenter 应用 DataTemplate 到 Content 属性,并将显示结果 UIElement 及其子元素(如果有)。 有关对象的详细信息 DataTemplate ,请参阅 数据模板化概述。
- 如果 ContentTemplateSelector 设置了的属性 ContentPresenter ,则 ContentPresenter 会向属性应用合适的, DataTemplate Content 并且 UIElement 会显示结果及其子元素(如果有)。
- 如果有 DataTemplate 与类型关联的 Content ,则会将其 ContentPresenter 应用 DataTemplate 到 Content 属性,并将显示生成的 UIElement 及其子元素(如果有)。
- 如果 Content 是一个 UIElement 对象,则 UIElement 显示。 如果 UIElement 已经有父级,则会出现异常。
- 如果有一个 TypeConverter 将类型转换 Content 为的 UIElement ,则将 ContentPresenter 使用 TypeConverter 并 UIElement 显示结果。
- 如果有一个 TypeConverter 将类型转换 Content 为字符串的,则将 ContentPresenter 使用 TypeConverter 并创建一个 TextBlock 来包含该字符串。 此时将显示TextBlock。
- 如果内容为,则 XmlElement 属性的值 InnerText 将显示在中 TextBlock 。
- 对 ContentPresenter 调用 ToString 方法 Content ,并创建

本文档详细介绍了WPF中的多种控件,如AccessText、AdornedElementPlaceholder、ColumnDefinition、ContentPresenter、ControlTemplate、Image、InkCanvas、ItemsPanelTemplate、ItemsPresenter、MediaElement、Page、RowDefinition、ScrollContentPresenter、TextBlock 和 Viewport3D。这些控件在构建用户界面时扮演着不同的角色,涉及布局、媒体播放、文本显示和自定义模板等功能。
最低0.47元/天 解锁文章
5547

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



