如何让网格在用户拉伸过程中改变其高度和背景图片?

时间:2016-06-27 09:35:04

标签: c# wpf visual-studio xaml

我正在WPF中执行一个项目(自定义窗口)。所以我面临一个问题。在主窗口中,我有边框,停靠面板和2个网格。它是垂直应用程序,用户需要从底部拉伸应用程序。如何使网格在用户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>

`

P.S这是我的第一个认真项目:3

1 个答案:

答案 0 :(得分:0)

首先,我必须评论你的编码方式是非常混乱的。您将许多不同的控件重叠为单个网格行。我发现你使用了“拖放”功能,我猜这对初学者来说很好。

现在来更严肃的话题。当你这样做时:

for idx in range(10):
  plt.figure()
  plt.imshow(image_list[idx])

将所有行定义指定为 <RowDefinition Height="auto" MinHeight="30"/> <RowDefinition Height="auto" MinHeight="558"/> 作为高度,您告诉Grid调整自身大小以适应所有内容。如果你希望这个外部网格适合屏幕大小(我猜是?),那么你需要至少一行auto单位的行定义。每个单元*表示在所有*内容占用后,它将占用所有可用空间的一部分。

告诉我们您想要的更多信息。请明确点。您已经提供了代码,因此我们知道控件的名称。而不是说“网格”和“背景”,告诉我们哪一个 - 因为你的代码显示了它们的许多实例。