Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF标记,限制DockPanel子级的高度_C#_Wpf_Xaml_Dockpanel - Fatal编程技术网

C# WPF标记,限制DockPanel子级的高度

C# WPF标记,限制DockPanel子级的高度,c#,wpf,xaml,dockpanel,C#,Wpf,Xaml,Dockpanel,我是WPF的新手,对绑定有很好的感觉,但我对标记不太熟悉。我经常使用Grid和DockPanel,可能不是以最有效的方式。我只是把插头插好,直到我得到一个看起来差不多正确的东西 关于下面的代码,我看到的是,图像占用了它所需的空间,以实现统一的增长。图像达到最大大小后,ItemList将增长以填充剩余空间(如果需要),然后是按钮。我想改变这一点,这样按钮可以从Viewbox中删除,图像只会增长到它进入按钮使用的空间为止 <DockPanel LastChildFill="False" >

我是WPF的新手,对绑定有很好的感觉,但我对标记不太熟悉。我经常使用Grid和DockPanel,可能不是以最有效的方式。我只是把插头插好,直到我得到一个看起来差不多正确的东西

关于下面的代码,我看到的是,图像占用了它所需的空间,以实现统一的增长。图像达到最大大小后,ItemList将增长以填充剩余空间(如果需要),然后是按钮。我想改变这一点,这样按钮可以从Viewbox中删除,图像只会增长到它进入按钮使用的空间为止

<DockPanel LastChildFill="False" >
    <Grid DockPanel.Dock="Bottom" x:Name="Images">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <DockPanel Grid.Column="0">
            <TextBlock DockPanel.Dock="Bottom" />
            <Button HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Image Stretch="Uniform" />
            </Button>
        </DockPanel>
        <DockPanel Grid.Column="1">
            <TextBlock DockPanel.Dock="Bottom" />
            <Button HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Image Stretch="Uniform" />
            </Button>
        </DockPanel>
    </Grid>
    <GroupBox DockPanel.Dock="Right" VerticalAlignment="Top" x:Name="ItemList">
        <ListView>
            <ListView.View>
                <GridView>
                    <GridViewColumn />
                </GridView>
            </ListView.View>
        </ListView>
    </GroupBox>
    <Viewbox DockPanel.Dock="Right" StretchDirection="DownOnly" VerticalAlignment="Top">
        <StackPanel Width="180" x:Names="Buttons">
            <Button Height="105" />
            <Button Height="105" />
        </StackPanel>
    </Viewbox>
</DockPanel>

谢谢-Derrick

我希望此代码能帮助您:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <DockPanel LastChildFill="False">
        <GroupBox DockPanel.Dock="Right" x:Name="ItemList">
            <DataGrid>
                <DataGrid.Columns>
                    <DataGridTextColumn />
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>
        <StackPanel DockPanel.Dock="Right" Width="180" x:Name="Buttons">
            <Button Height="105" />
            <Button Height="105" />
        </StackPanel>
    </DockPanel>
    <Grid x:Name="Images" Grid.Row="1" Style="{StaticResource HideImages}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <DockPanel Grid.Column="0">
            <TextBlock DockPanel.Dock="Bottom" />
            <Button HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Image Stretch="Uniform" />
            </Button>
        </DockPanel>
        <DockPanel Grid.Column="1">
            <TextBlock DockPanel.Dock="Bottom" />
            <Button HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Image Stretch="Uniform" />
            </Button>
        </DockPanel>
    </Grid>
</Grid>

清楚地解释你想要什么,并尝试提供一个直观的例子,目前还不清楚。@Aybe我已经添加了一个图表,希望能有所帮助。仍然不清楚,我已经运行了你的代码,但结果很愚蠢。顶部有两个巨大的按钮,右侧有一个小按钮,底部又有两个巨大的按钮,这真让人困惑:D你想实现什么?@Aybe在ItemList中找到的数据网格绑定到一个要查看的项目集合。底部大按钮中包含的图像将绑定到ItemList中的选定项。这些图像允许用户使用顶部附近的较小按钮将项目分配到两个组中的一个组。如果需要,底部的大按钮可用于以新形式最大化图像,以获得更好的外观。您好,我想知道您的项目进展如何,您能否发布您当前视图的图片,TBH我正在努力理解要求,但这只是我。我将尝试这个,但是,我的印象是,定义的行定义将为DockPanel和网格的每个行提供50%的空间?是的。这是合适的场景吗?不幸的是,我需要底部的按钮尽可能大,而不会干扰顶部的按钮,也不会过度拉伸到包含的图像。
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <DockPanel LastChildFill="False">
        <GroupBox DockPanel.Dock="Right" x:Name="ItemList">
            <DataGrid>
                <DataGrid.Columns>
                    <DataGridTextColumn />
                </DataGrid.Columns>
            </DataGrid>
        </GroupBox>
        <StackPanel DockPanel.Dock="Right" Width="180" x:Name="Buttons">
            <Button Height="105" />
            <Button Height="105" />
        </StackPanel>
    </DockPanel>
    <Grid x:Name="Images" Grid.Row="1" Style="{StaticResource HideImages}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <DockPanel Grid.Column="0">
            <TextBlock DockPanel.Dock="Bottom" />
            <Button HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Image Stretch="Uniform" />
            </Button>
        </DockPanel>
        <DockPanel Grid.Column="1">
            <TextBlock DockPanel.Dock="Bottom" />
            <Button HorizontalAlignment="Center" VerticalAlignment="Bottom">
                <Image Stretch="Uniform" />
            </Button>
        </DockPanel>
    </Grid>
</Grid>