继续聊WPF——BulletDecorator控件
2011-11-13 11:58
429 查看
这是一个很简单的控件,无非就是控制项目的布局方式,其布局方式只有两种:从左到右,从右到左。
一、从左到右
二、从右到左
布局方向由FlowDirection属性来决定,所以我说这个控件非常简单
上面的截图的XAML如下:
下面例子展示一个带文本框的项:
为什么这里都用到Label控件而不是TextBlock控件呢?你可以试试,如果放置TextBlock控件,就不能居中对齐了,BulletDecorator控件的Child内容如果是TextBlock的话,那么,Bullet将与其上端对齐,也就是Top,哪些是居中,它也始终保持与基线对齐,这个在MSDN上也有说明,因此,在BulletDecorator控件中如果希望放置文本内容但又希望其保持居中对齐的话,就得用TextBlock以外的控件,显示提示文本,Label控件非常合适。
BulletDecorator控件的Bullet属性用于指定在列表项中显示的项目符号,而Child属性才是放置内容的地方。
每个BulletDecorator控个只包含一个项,如果你希望多项按一定方向或次序排列的话,你应该将其放到一个StaticPanel中,当然,BulletDecorator更多的时候应当用于复杂控件的部件或某部分,因为BulletDecorator是在System.Windows.Controls.Primitives命名空间中定义的,该命名空间中定义的控件都是作为复杂控件模板的一部分而用的,比如这个BulletDecorator控件可用于CheckBox、ListBoxItem等控件模板的布局。
一、从左到右
二、从右到左
布局方向由FlowDirection属性来决定,所以我说这个控件非常简单
上面的截图的XAML如下:
<BulletDecorator HorizontalAlignment="Center" Background="#AACC01" VerticalAlignment="Center" Height="21" Width="76" FlowDirection="RightToLeft" Margin="5,10"> <BulletDecorator.Bullet> <Rectangle RadiusX="2" RadiusY="2" Stroke="Black" StrokeThickness="0.5" Height="16" Width="16"> <Rectangle.Fill> <RadialGradientBrush Center="0.5,0.5" RadiusX="0.5" RadiusY="0.5" > <GradientStop Color="FloralWhite" Offset="0"/> <GradientStop Color="DarkGoldenrod" Offset="1"/> </RadialGradientBrush> </Rectangle.Fill> </Rectangle> </BulletDecorator.Bullet> <Label FontSize="10" Width="70">带矩形的项</Label> </BulletDecorator>
下面例子展示一个带文本框的项:
<BulletDecorator Grid.Row="1" Margin="19.992,5.136,27.132,5" Height="29" FlowDirection="RightToLeft" VerticalAlignment="Center" HorizontalAlignment="Center" Background="LightGray"> <BulletDecorator.Bullet> <TextBox FlowDirection="LeftToRight" Margin="2,2,5,2" Width="126.378" /> </BulletDecorator.Bullet> <BulletDecorator.Child> <Label FontSize="12" Height="24.276" Width="100.674" FlowDirection="LeftToRight">请输入您的鸟名:</Label> </BulletDecorator.Child> </BulletDecorator>
为什么这里都用到Label控件而不是TextBlock控件呢?你可以试试,如果放置TextBlock控件,就不能居中对齐了,BulletDecorator控件的Child内容如果是TextBlock的话,那么,Bullet将与其上端对齐,也就是Top,哪些是居中,它也始终保持与基线对齐,这个在MSDN上也有说明,因此,在BulletDecorator控件中如果希望放置文本内容但又希望其保持居中对齐的话,就得用TextBlock以外的控件,显示提示文本,Label控件非常合适。
BulletDecorator控件的Bullet属性用于指定在列表项中显示的项目符号,而Child属性才是放置内容的地方。
每个BulletDecorator控个只包含一个项,如果你希望多项按一定方向或次序排列的话,你应该将其放到一个StaticPanel中,当然,BulletDecorator更多的时候应当用于复杂控件的部件或某部分,因为BulletDecorator是在System.Windows.Controls.Primitives命名空间中定义的,该命名空间中定义的控件都是作为复杂控件模板的一部分而用的,比如这个BulletDecorator控件可用于CheckBox、ListBoxItem等控件模板的布局。
相关文章推荐
- 继续聊WPF——BulletDecorator控件
- 继续聊WPF——BulletDecorator控件
- 继续聊WPF——设置网格控件列标题的样式
- 继续聊WPF——设置网格控件列标题的样式
- 继续聊WPF——设置网格控件列标题的样式
- 继续聊WPF——Expander控件(2)
- 继续聊WPF——Expander控件(2)
- 继续聊WPF——Expander控件(2)
- WPF的BulletDecorator 对齐控件
- 继续聊WPF——Expander控件(2)
- 继续聊WPF——Expander控件(1)
- 继续聊WPF——Expander控件(1)
- 继续聊WPF——Thumb控件
- 继续聊WPF——自定义CheckBox控件外观
- 继续聊WPF——Expander控件(1)
- 继续聊WPF——自定义CheckBox控件外观
- 继续聊WPF——Expander控件(1)
- 继续聊WPF——设置网格控件列标题的样式
- 继续聊WPF——Thumb控件
- 继续聊WPF——自定义CheckBox控件外观