品牌网站查询,电子工程师网站,lnmp wordpress 不显示主题,门户网站管理系统严格来说#xff0c;Border并不是一个布局控件#xff0c;因为它并不是Panel的子类#xff0c;而是Decorator装饰器的子类#xff0c;而Decorator继承于FrameworkElement。我们要先看看它的父类Decorator。
public class Decorator : FrameworkElement, IAddChild
{public…严格来说Border并不是一个布局控件因为它并不是Panel的子类而是Decorator装饰器的子类而Decorator继承于FrameworkElement。我们要先看看它的父类Decorator。
public class Decorator : FrameworkElement, IAddChild
{public Decorator();public virtual UIElement Child { get; set; }protected override int VisualChildrenCount { get; }protected internal override IEnumerator LogicalChildren { get; }protected override Size ArrangeOverride(Size arrangeSize);protected override Visual GetVisualChild(int index);protected override Size MeasureOverride(Size constraint);}Decorator 装饰器只有一个Child 属性说明Decorator只能容纳一个子元素UIElement也就是Border只能容纳一个子元素。
再看看Border的结构定义
public class Border : Decorator
{public static readonly DependencyProperty BorderThicknessProperty;public static readonly DependencyProperty PaddingProperty;public static readonly DependencyProperty CornerRadiusProperty;public static readonly DependencyProperty BorderBrushProperty;public static readonly DependencyProperty BackgroundProperty;public Border();public Thickness BorderThickness { get; set; }public Thickness Padding { get; set; }public CornerRadius CornerRadius { get; set; }public Brush BorderBrush { get; set; }public Brush Background { get; set; }protected override Size ArrangeOverride(Size finalSize);protected override Size MeasureOverride(Size constraint);protected override void OnRender(DrawingContext dc);}BorderThickness设置Border边框的厚度像素宽度。Padding设置子元素相对于Border边框的距离。CornerRadius设置Border的圆角。BorderBrush设置Border边框的颜色画刷。Background设置Border的背景颜色画刷。
正是因为Border有这么多实用的属性 所以 我们通常在布局界面时Border装饰器控件是首选。 WrapPanel Margin10Border Height35 Margin10 Padding5 BorderThickness1 BorderBrushGrayTextBlock Text矩形 - Border控件 Margin5 //BorderBorder Height35 Margin10 Padding5 BorderThickness1 BorderBrushGray CornerRadius20TextBlock Text椭圆 - Border控件 Margin5 //BorderBorder Width150 Height150 Margin10 Padding5 BorderThickness1 BackgroundRed BorderBrushGray CornerRadius75TextBlock Text圆形Border控件 Margin5 HorizontalAlignmentCenter FontSize16 FontWeightBold VerticalAlignmentCenter ForegroundWhite//Border/WrapPanel我们分别写了3个Border第一个Border被设计成矩形第二个Border增加了圆角属性第三个Border通过CornerRadius属性将值设置为宽度或高度的一半就形成了一个正圆。
GridSplitter分割窗口
GridSplitter控件用来分割窗体的布局必须放在Grid栅格控件中配合使用通过鼠标按住GridSplitter进行左右或上下拖动即可调整行列尺寸。
注意
如果你希望GridSplitter控件可以水平调整左右的Grid列宽时那么HorizontalAlignment属性必须设置为Stretch或者Center。如果你希望GridSplitter控件可以垂直调整行高那么VerticalAlignment属性必须设置为Stretch或者Center。ShowsPreview属性表示拖动时是否及时绘制调整尺寸。 GridGrid.ColumnDefinitionsColumnDefinition/ColumnDefinition Widthauto/ColumnDefinition//Grid.ColumnDefinitionsBorder Grid.Column0 BackgroundLightBlueTextBlock TextWrappingWrap Padding10 LineHeight201111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111/TextBlock/BorderGridSplitter Grid.Column1 Width5 HorizontalAlignmentCenter ShowsPreviewFalse/Border Grid.Column2 BackgroundLightCoralTextBlock TextWrappingWrap Padding10 LineHeight20222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222/TextBlock/Border/Grid最好是为GridSplitter单独分配一行或者一列同时GridSplitter需要跨越整行或整列这样的效果会更好。
如上面的代码所示我们在Grid中分割了3个单元格3列将GridSplitter居在放置简单设置一下GridSplitter的属性就可以达到我们的目的了。