如何使一个WPF窗口响应 [英] How to Make a WPF Window Responsive

查看:315
本文介绍了如何使一个WPF窗口响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是混合式刚开始与WPF。

I'm using Blend Expression and just started with WPF.

我试图使可容纳多个网格,将重新大小的一个窗口,窗口响应。根据窗口大小为最小宽度

I'm trying to make a window responsive window which can accommodate multiple Grids and will be re sized as per the window size to a minimum width.

它将是这样的:

到目前为止我的代码:

<Window x:Class="Blend.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" WindowState="Maximized">
<Grid>
<Border CornerRadius="5" BorderBrush="RoyalBlue" BorderThickness="1" 
                Padding="5" HorizontalAlignment="Left" Margin="20,10,0,0" 
                VerticalAlignment="Top" Height="211.5" Width="484.5">
<Grid Background="#FFEDF3F8">

</Grid>
</Border>
<Border CornerRadius="5" BorderBrush="RoyalBlue" BorderThickness="1" 
    Padding="5" Margin="523.333,10,16.334,283.5">
    <Grid Background="#FFEDF3F8"/>
</Border>
<Border CornerRadius="5" BorderBrush="RoyalBlue" BorderThickness="1" 
    Padding="5" Margin="21.333,234,16.334,144">
    <Grid Background="#FFEDF3F8"/>
</Border>
<Border CornerRadius="5" BorderBrush="RoyalBlue" BorderThickness="1" 
    Padding="5" Margin="21.333,372,16.334,31.5">
    <Grid Background="#FFEDF3F8"/>
</Border>
<Button Content="Button" HorizontalAlignment="Left" Margin="626.833,478.5,0,0"
 VerticalAlignment="Top" Width="49" Background="#FF00458C"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="693.166,478.5,0,0" 
VerticalAlignment="Top" Width="49" Background="#FF00458C"/>
</Grid>
</Window>



我已经试过2这里的东西一个是保证金和其他正在使用'路线'与宽度高度

I have tried 2 Things here One is Margin and other is Using 'Alignments' with Width and Height.

不知道这将解决我的目的,其次将它的屏幕尺寸回应与否。

Not sure which will solve my purpose and secondly will it respond to the screen size or not.

我阅读有关动态电网使用*但这似乎并不在这里工作。

I Read about Dynamic Grid using * but that does not seems to work here.

谢谢,

推荐答案

您不是使用以正确的方式在网格

You're not using the grid in the correct way.

WPF网格已经允许以设置列和行的性质。然后,你会把网格内的元素,其中行/列,他们应该去设置的。

WPF Grids have a property that allows to set columns and rows. Then, you would put elements inside the grid and set in which row/column they should go.

当然,你可以有内部网格等。

Of course you can have grids inside grid and so on.

然后,您可以用WIDTH =2 *之类的东西玩尽列比其它更大或更小,响应。

You can then play with the Width="2*" and things like that to make columns larger or smaller than other, "responsively".

下面的代码应该给你你试图达到什么东西类似

The code below should give you something "similar" to what you try to achieve.

<Grid>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="2*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

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

    <Grid Grid.Row="0"
          Grid.Column="0"
          Background="Red" />

    <Grid Grid.Row="0"
          Grid.Column="1"
          Background="Blue" />

    <Grid Grid.Row="1"
          Grid.Column="0"
          Grid.ColumnSpan="2"
          Background="Violet" />

    <Grid Grid.Row="2"
          Grid.Column="0"
          Grid.ColumnSpan="2"
          Background="Green" />

    <StackPanel Grid.Row="3"
                Grid.ColumnSpan="2"
                Orientation="Horizontal">
         <Button>OK</Button>
         <Button>Cancel</Button>
    </StackPanel>
</Grid>

您可以用*和自动打的列和行的宽度和高度, *总是定义为当前窗口的宽度或高度的百分比。如果你有*的一列和另一用2 *,一个为2 *将两倍所述一个只用*作为大,这将使得一个2/3 1/3分离。

You can play with "*" and "Auto" for width and height of the column and rows, "*" is always defined as a "percent" of the current windows' width or height. If you have one column with "*" and another with "2*", the one with "2*" will be twice as big as the one with only "*", which will make a 2/3 1/3 separation.

自动意味着它将采取较小的宽度或高度,允许以显示该柱的内部

The "Auto" means that it will take "the smaller width or height that allows to show the inside of the column".

这篇关于如何使一个WPF窗口响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆