WPF学习总结和记录(七)-尺寸缩放 定位 上

来源:互联网 发布:广点通优化思路 编辑:程序博客网 时间:2024/06/05 23:52

尺寸

1 高度宽度

MinHeight MaxHeight MinWidth MaxWidth指定一个可以接受的范围

 

2 Margin Padding

Margin控制元素边界以外多少空间 Padding控制元素边界内多少空间

 

        <Label Padding="0" Background="OrangeRed">0</Label>
        <Label Padding="10" Background="OrangeRed">10</Label>
        <Label Padding="20,5" Background="OrangeRed">20,5</Label>
        <Label Padding="0,10,20,30" Background="OrangeRed">0,10,20,30</Label>

等同于code

myLabel.Margin = new Thickness(10);

myLabel.Margin = new Thickness(0,10,20,30);

 

3. Visibility

包括三种

Visble 可见的

Collspsed 折叠的

Hidden 隐藏的

 

折叠元素尺寸为0 ;隐藏还是原来的尺寸

 

例如

    <StackPanel  Background="Aqua">        
        <Button Visibility="Collapsed">Collapsed button</Button>
        <Button Visibility="Hidden">Hidden button</Button>
        <Button Visibility="Visible">Visible button</Button>
    </StackPanel>

 

效果

可以看出折叠的没占位置  隐藏的占了一个按钮的位置

 

控制定位

1 对齐方式

HorizontalAlignment: Left, Center, Right, Stretch

VerticalAlignment:Top, Center, Bottom, Stretch

 

例子

    <StackPanel>
        <Button HorizontalAlignment="Left" Background="Red">Left</Button>
        <Button HorizontalAlignment="Center" Background="Red">Center</Button>
        <Button HorizontalAlignment="Right" Background="Red">Right</Button>
        <Button HorizontalAlignment="Stretch" Background="Red">Stretch</Button>

    </StackPanel>

效果如下

 

2 内容对齐

HorizontalContentAlignment, VerticalContentAlignment 决定控件内容如何填满控件内部空间。

 

    <StackPanel>     

        <Button HorizontalContentAlignment="Left" Background="Red">Left</Button>
        <Button HorizontalContentAlignment="Center" Background="Red">Center</Button>
        <Button HorizontalContentAlignment="Right" Background="Red">Right</Button>
        <Button HorizontalContentAlignment="Stretch" Background="Red">Stretch</Button>

    </StackPanel>

 

3 FlowDirection

控制元素内部流的方向;包括LeftToRight; RightToLeft

     <Button FlowDirection="LeftToRight" HorizontalContentAlignment="Left" Height="40" Background="Red">LeftToRight</Button>
     <Button FlowDirection="RightToLeft" HorizontalContentAlignment="Left" Height="40" Background="Red">RightToLeft</Button>

注意他不会影响字母的顺序

 

 

变换

1 RenderTransformOrigin

默认(0,0)

(0,0)左上    (0,1)左下   (1,0)右上   (1,1)  右下 (0.5,0.5)表示中心

 

例子

        <Button RenderTransformOrigin="0,0" Background="AliceBlue">
            <Button.RenderTransform>
                <RotateTransform Angle="45" />
            </Button.RenderTransform>
            Rotated 45
        </Button>

 

 

转换字体角度

<Button  Background="AliceBlue">
            <TextBlock RenderTransformOrigin="0.5,0.5">
                <TextBlock.RenderTransform>
                     <RotateTransform Angle="45" />
                </TextBlock.RenderTransform>
            Rotated 45
            </TextBlock>
        </Button>

 

 

原创粉丝点击