开发者

Positioning controls in WPF

The WPF application has been customized in a way such that it will be launched on top and in full screen mode.

This application will be deployed on screens wit开发者_如何学Pythonh varying resolutions.

This application contains buttons and image box.

The image box should be on the top and in the center

Please suggest how to align these buttons and image boxes in the application

If we have go by finding the co-ordinates then how it should be done

Also suggest if any other method can be followed


There are several control for positioning elements in WPF, e.g. DockPanel, StackPanel or Grid. Additionally, you can take a look at the properties HorizontalAlignment, VerticalAlignment, HorizontalContentAlignment... These controls manage positioning / normally you don't need to calculate positions yourself


How's this?

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Image Grid.Row="0" Source="image.jpg"/>
    <StackPanel Grid.Row="1" Orientation="Horizontal">
        <Button>Button 1</Button>
        <Button>Button 2</Button>
        <Button>etc...</Button>
    </StackPanel>
</Grid>

This puts the image above the buttons (by placing in the appropriate rows in a grid). The height of the second row is determined by the height of the buttons (Height="Auto") and then the top row will just take up the rest of the available space (Height="*").

The StackPanel (with a horizontal orientation) then just places the buttons one after the other...but you could use a ToolBar or some other layout control that will meet your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜