[英]How do I make the grid to change its height and its background picture within user`s stretching?
I am doing a project in WPF (Custom windows). 我正在WPF(自定义窗口)中做一个项目。 So I am facing one question. 所以我面临一个问题。 In the main window I have border, dock panel and 2 grids. 在主窗口中,我有边框,停靠面板和2个网格。 It is vertical app and the user needs to stretch the app from the bottom. 它是垂直应用程序,用户需要从底部扩展应用程序。 How do I make the grid to change its height and its background picture within user s stretching?[enter image description here][1] For example, from 270x1 to 270x330 by simple dragging the bottom to the down.[enter image description here][1]
如何使网格在用户s stretching?[enter image description here][1] For example, from 270x1 to 270x330 by simple dragging the bottom to the down.[enter image description here][1]
范围内改变其高度和背景图片s stretching?[enter image description here][1] For example, from 270x1 to 270x330 by simple dragging the bottom to the down.[enter image description here][1]
<Grid Width="270" Margin="4,2,0.5,0" Height="588" HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="auto" MinHeight="30"/>
<RowDefinition Height="auto" MinHeight="558"/>
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush/>
</Grid.Background>
<Border x:Name="MainBorder" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="270" Grid.RowSpan="2" MouseLeftButtonDown="MainBorder_MouseLeftButtonDown">
<Border.Background>
<ImageBrush ImageSource="atopbg.png"/>
</Border.Background>
</Border>
<Button x:Name="buttonclose" Content="" HorizontalAlignment="Left" Margin="243,10,0,0" VerticalAlignment="Top" Width="18" Height="18" Click="buttonclose_Click" BorderBrush="#FFDEECF2">
<Button.Background>
<ImageBrush ImageSource="close.png"/>
</Button.Background>
</Button>
<Button x:Name="buttonhide" Content="" HorizontalAlignment="Left" Margin="220,10,0,0" VerticalAlignment="Top" Width="18" Height="18" Click="buttonhide_Click" BorderBrush="#FFE6EDF1">
<Button.Background>
<ImageBrush ImageSource="collapse.png"/>
</Button.Background>
</Button>
<Button x:Name="buttonsettings" HorizontalAlignment="Left" Margin="197,10,0,0" VerticalAlignment="Top" Width="18" Height="18" BorderBrush="#FFEBF0F3" Click="buttonsettings_Click">
<Button.Background>
<ImageBrush ImageSource="settings.png"/>
</Button.Background>
</Button>
<Label x:Name="label" HorizontalAlignment="Left" Margin="172,46,0,0" VerticalAlignment="Top" Grid.Row="1" Height="10" Width="10">
<Label.Background>
<ImageBrush/>
</Label.Background>
</Label>
<Label x:Name="label1" Content="" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Width="84" Height="29">
<Label.Background>
<ImageBrush ImageSource="logo.png"/>
</Label.Background>
</Label>
<Grid HorizontalAlignment="Left" Height="86" Margin="0,472,0,0" VerticalAlignment="Top" Width="270" Grid.Row="1">
<Grid.Background>
<ImageBrush ImageSource="botbg.png" Stretch="Uniform"/>
</Grid.Background>
</Grid>
<DockPanel HorizontalAlignment="Left" Height="140" Margin="0,2,0,0" Grid.Row="1" VerticalAlignment="Top" Width="270">
<DockPanel.Background>
<ImageBrush ImageSource="btopbg.png"/>
</DockPanel.Background>
</DockPanel>
<GridSplitter x:Name="gridSplitter" HorizontalAlignment="Left" Height="330" Margin="0,142,0,0" Grid.Row="1" VerticalAlignment="Top" Width="270" ResizeDirection="Rows" DragDelta="gridSplitter_DragDelta" ResizeBehavior="PreviousAndCurrent">
<GridSplitter.Background>
<ImageBrush ImageSource="midbg.png"/>
</GridSplitter.Background>
</GridSplitter>
</Grid>
` `
PS It`s my first serious project:3 PS这是我的第一个认真的项目:3
Firstly, I have to comment that your way of coding this is quite messy. 首先,我必须评论一下,您的编码方式非常混乱。 You are overlapping many different controls into a single Grid row. 您将许多不同的控件重叠到一个网格行中。 I figured out you used the "drag and drop" feature, which I guess is fine for beginners. 我发现您使用了“拖放”功能,我认为这对初学者来说很好。
Now to more serious topic. 现在来个严肃的话题。 When you do this: 执行此操作时:
<RowDefinition Height="auto" MinHeight="30"/>
<RowDefinition Height="auto" MinHeight="558"/>
Having all row definitions specifying auto
as height, you are telling Grid to resize itself to fit all the contents. 在所有行定义都将auto
指定为高度的情况下,您要告诉Grid调整自身大小以适合所有内容。 If you want this outer Grid to fit to screen size (I presume?), then you need to have at least one row definition that is of *
unit. 如果您希望外部网格适合屏幕尺寸(我想是?),那么您至少需要有一个*
单位的行定义。 Each unit *
means that it will take one portion of all the available spaces left after all the auto
contents have occupied. 每个单位*
表示将占用所有auto
内容后剩余的所有可用空间的一部分。
Tell us more about what you want. 告诉我们更多有关您想要的信息。 Be specific. 请明确点。 You have already given codes, so we know the names of controls. 您已经提供了代码,所以我们知道控件的名称。 Instead of saying "Grid" and "background", tell us which one - because your codes show many instances of them. 不要告诉我们“网格”和“背景”,而是告诉我们哪一个-因为您的代码显示了许多实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.