简体   繁体   English

在状态栏中调整项目的大小-WPF

[英]Resizing items in a statusbar - WPF

How can I arrange the items on a statusbar uniformly? 如何将项目统一排列在状态栏上? Because when I run the project and maximize the window, all the items are placed on the left most corner. 因为当我运行项目并最大化窗口时,所有项目都放置在最左角。

 <StatusBar Grid.Row="3" Background="#FFDED9D9"  Grid.ColumnSpan="9" Margin="2,29,0,1"  >


<Label Content="Running"/>
<Separator >
</Separator>
<Label Content="           " />
<Separator>
</Separator>
<Label Content="Object" />
<Separator>
</Separator>
<Label Content="Status:" />
<Rectangle Height="19" RenderTransformOrigin="0.5,0.5" Width="18"    Fill="#FFFFFDFD" >
    <Rectangle.RenderTransform>
        <TransformGroup>
            <ScaleTransform ScaleY="-1" ScaleX="-1"/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
        </TransformGroup>
    </Rectangle.RenderTransform>
</Rectangle>
<Separator> </Separator>
<Button Content="Show" Height="25.96" Width="117.113" ></Button>
<Separator> </Separator>
<ProgressBar Value="55" Height="20" Width="85"  ></ProgressBar>

        </StatusBar>

Add a Grid to the StatusBar and add as many columns as needed with their widths set to * 将网格添加到StatusBar并根据需要添加任意数量的列,其宽度设置为*

<StatusBar>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Label Grid.Column="0" />
        <Label Grid.Column="1" />
        <Label Grid.Column="2" />
        <Label Grid.Column="3" />
    </Grid>
</StatusBar>

Use an UniformGrid as template, it is made for that. 使用UniformGrid作为模板,就是为此而设计的。 Everything in the Statusbar will align automatically. 状态栏中的所有内容都会自动对齐。 You don't need to specify column ids for that. 您无需为此指定列ID。 You might need to take out those separators. 您可能需要取出那些分隔符。

<StatusBar DockPanel.Dock="Bottom">
    <StatusBar.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Rows="1"/>
        </ItemsPanelTemplate>
    </StatusBar.ItemsPanel>

    <Label Content="..." />
    <Label Content="..." />
    <Label Content="..." />
    <Label Content="..." />
</StatusBar>

对每个标签和按钮尝试此操作,然后将统一对齐

 HorizontalContentAlignment="Center" VerticalAlignment="Stretch" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM