我如何使网格改变其高度和背景图片在用户的拉伸

本文关键字:背景图片 用户 高度 何使 网格 改变 | 更新日期: 2023-09-27 17:52:38

我在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。3

我如何使网格改变其高度和背景图片在用户的拉伸

首先,我必须说明您的编码方式非常混乱。您正在将许多不同的控件重叠到单个Grid行中。我发现你用的是"拖放"功能,我想这对初学者来说还行。

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

    <RowDefinition Height="auto" MinHeight="30"/>
    <RowDefinition Height="auto" MinHeight="558"/>

所有的行定义指定auto作为高度,你告诉网格调整自己的大小,以适应所有的内容。如果你想要这个外部网格适合屏幕大小(我猜?),那么你需要有至少一行定义是*单位。每个单元*意味着在所有auto内容被占用后,它将占用所有可用空间的一部分。

告诉我们你想要什么。要具体。您已经给出了代码,所以我们知道控件的名称。而不是说"Grid"answers"background",告诉我们是哪一个-因为你的代码显示了它们的许多实例。