代码之家  ›  专栏  ›  技术社区  ›  Europa

WPF主左高100%,主右高100%,页脚

wpf
  •  0
  • Europa  · 技术社区  · 6 年前

    我已经创建了以下设计与主左,主右和页脚。

    不过,我希望主左是100%的高度,这样深灰色的背景颜色一直到页脚。 我试过设置height=*,但没用。

    我的设计: enter image description here

    新建项目窗口.xaml

    <Window x:Class="QuickImageForensicsWPF.NewProject.NewProjectWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:QuickImageForensicsWPF.NewProject"
            mc:Ignorable="d"
            Title="New Project | Quick Image Forensics" Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}" Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}"  Top="0" Left="0">
    
        <Window.Resources>
            <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="..\res\style\Btn.xaml" />
                    <ResourceDictionary Source="..\res\style\Input.xaml" />
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
        </Window.Resources>
    
    
        <Grid Background="#FF45474A">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
    
            <!-- Main -->
            <StackPanel x:Name="stackPanelMain" Grid.Row="0" Grid.Column="0" >
                <Grid Background="#FF45474A">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="400" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
    
                    <StackPanel x:Name="stackPanelLeft" Grid.Row="0" Grid.Column="0" Background="#FF393939" Margin="0,0,20,0">
                        <!-- Left content -->
                        <Label x:Name="labelProjects"  Content="New project" Margin="0,20,0,0" FontSize="16" Foreground="#FFBABAA8" FontWeight="Bold"/>
                        <Label x:Name="labelNewProjectStep01" Content="Project information" Margin="0,0,0,0" FontSize="14" Foreground="#FFBABAA8" FontStyle="Italic" />
                        <Label x:Name="labelNewProjectStep02" Content="Automated tasks" Margin="0,0,0,0" FontSize="14" Foreground="#FFBABAA8"  />
                        <Label x:Name="labelNewProjectStep03" Content="Search" Margin="0,0,0,0" FontSize="14" Foreground="#FFBABAA8" />
                        <!-- //Left content -->
                    </StackPanel>
                    <StackPanel x:Name="stackPanelRight" Grid.Row="0" Grid.Column="1">
                        <!-- Right content -->
                        <DockPanel x:Name="dockPanelMain" LastChildFill="False">
                            <local:NewProjectStep01ProjectInformationUserControl x:Name="newProjectStep01ProjectInformationUserControl" Panel.ZIndex="0" />
                            <local:NewProjectStep02AutomatedTasksUserControl x:Name="NewProjectStep02AutomatedTasksUserControl" Panel.ZIndex="1" />
                            <local:NewProjectStep03SearchUserControl x:Name="NewProjectStep03SearchUserControl" Panel.ZIndex="2" />
                        </DockPanel>
                        <!-- //Right content -->
                    </StackPanel>
                </Grid>
            </StackPanel>
            <!-- //Main -->
    
    
            <!-- Footer -->
            <StackPanel x:Name="stackPanelFooter" Grid.Row="1" Grid.Column="0">
                <Border BorderBrush="#FF323232" BorderThickness="1" DockPanel.Dock="Top" Padding="0,0,0,0">
                    <Grid Background="#FF45474A">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="400" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
    
                        <StackPanel Grid.Column="1" Orientation="Horizontal" Margin="0,20,0,20">
                            <Button x:Name="buttonPrevious" Content=" Previous " VerticalAlignment="Bottom" Click="buttonPrevious_Click" Style="{StaticResource btn_default}" HorizontalAlignment="Left"  Margin="0,0,10,0" />
                            <Button x:Name="buttonNext" Content=" Next " VerticalAlignment="Bottom" Click="buttonNext_Click" Style="{StaticResource btn_default_success}" HorizontalAlignment="Left" />
                        </StackPanel>
                    </Grid>
                </Border>
            </StackPanel>
            <!-- //Footer -->
    
        </Grid>
    </Window>
    

    程序是C#WPF和.NETFramework v4.7.2。

    0 回复  |  直到 6 年前
        1
  •  1
  •   Sats    6 年前

    对于Main,我替换了 stackpanel 添加网格布局 VerticalAlignment="Stretch" .

    <Grid x:Name="stackPanelMain" Grid.Row="0" Grid.Column="0"  VerticalAlignment="Stretch"  >
                <Grid Background="#FF45474A"  VerticalAlignment="Stretch"  >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="400*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="400" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
    
    
                    <StackPanel x:Name="stackPanelLeft" Grid.Row="0" Grid.Column="0" Background="#FF393939" Margin="0,0,20,0">
                        <!-- Left content -->
                        <Label x:Name="labelProjects"  Content="New project" Margin="0,20,0,0" FontSize="16" Foreground="#FFBABAA8" FontWeight="Bold"/>
                        <Label x:Name="labelNewProjectStep01" Content="Project information" Margin="0,0,0,0" FontSize="14" Foreground="#FFBABAA8" FontStyle="Italic" />
                        <Label x:Name="labelNewProjectStep02" Content="Automated tasks" Margin="0,0,0,0" FontSize="14" Foreground="#FFBABAA8"  />
                        <Label x:Name="labelNewProjectStep03" Content="Search" Margin="0,0,0,0" FontSize="14" Foreground="#FFBABAA8" />
                        <!-- //Left content -->
                    </StackPanel>
                    <StackPanel x:Name="stackPanelRight" Grid.Row="0" Grid.Column="1">
                        <!-- Right content -->
                        <DockPanel x:Name="dockPanelMain" LastChildFill="False">
                            <!--<local:NewProjectStep01ProjectInformationUserControl x:Name="newProjectStep01ProjectInformationUserControl" Panel.ZIndex="0" />
                            <local:NewProjectStep02AutomatedTasksUserControl x:Name="NewProjectStep02AutomatedTasksUserControl" Panel.ZIndex="1" />
                            <local:NewProjectStep03SearchUserControl x:Name="NewProjectStep03SearchUserControl" Panel.ZIndex="2" />-->
                        </DockPanel>
                        <!-- //Right content -->
                    </StackPanel>
                </Grid>
            </Grid>