继续聊WPF——BulletDecorator控件

这是一个很简单的控件,无非就是控制项目的布局方式,其布局方式只有两种:从左到右,从右到左。
一、从左到右

二、从右到左

布局方向由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等控件模板的布局。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值