ContentProperty

来源:互联网 发布:高级有限元分析软件 编辑:程序博客网 时间:2024/05/21 00:53

ContentPropertyAttribute主要用于Xaml的简化.

<TextBlock.Foreground><RadialGradientBrush><RadialGradientBrush.GradientStops><GradientStopCollection><GradientStop Offset="0" Color="Transparent" /><GradientStop Offset="1" Color="Red" /></GradientStopCollection></RadialGradientBrush.GradientStops></RadialGradientBrush></TextBlock.Foreground>

首先剔除GradientStopCollenction

<TextBlock.Foreground><RadialGradientBrush><RadialGradientBrush.GradientStops><GradientStop Offset="0" Color="Transparent" /><GradientStop Offset="1" Color="Red" /></RadialGradientBrush.GradientStops></RadialGradientBrush></TextBlock.Foreground>

其次,因为

[ContentPropertyAttribute("GradientStops", true)]public abstract class GradientBrush : Brush

所以,可以剔除RadialGradientBrush.GradientStops,变成

<TextBlock.Foreground><RadialGradientBrush><GradientStop Offset="0" Color="Transparent" /><GradientStop Offset="1" Color="Red" /></RadialGradientBrush></TextBlock.Foreground>

--------------------------------------------------------------------------------------------------

又如

[ContentPropertyAttribute("Children", true)]public abstract class Panel : FrameworkElement[ContentPropertyAttribute("Content", true)]public class UserControl : Control

都是给与Xaml元素默认的可省略内部元素标签

0 0
原创粉丝点击