gpt4 book ai didi

wpf - 在 RibbonGroup 内水平拉伸(stretch) WPF 网格

转载 作者:行者123 更新时间:2023-12-02 00:15:24 25 4
gpt4 key购买 nike

如何在 RibbonGroup 内水平拉伸(stretch) WPF Grid?尽管有 Horizo​​ntalAlignment 属性,但它不会拉伸(stretch)。

<Window x:Name="FrmMain" x:Class="PhotoCell.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PhotoCell" Height="386.821" Width="757.701" WindowState="Maximized">
<Grid>
<Image x:Name="imgMain" Margin="10,142,10,9"/>
<Ribbon VerticalAlignment="Top">
<RibbonTab Header="Home" Height="88" VerticalAlignment="Top">
<RibbonGroup Header="Save/Load" Height="88" Margin="0" VerticalAlignment="Top" Width="90">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<RibbonButton x:Name="cmdLoadImage" Background="#FFFFC500" Label="Load" Click="cmdLoadImage_Click" Margin="10,10,10,0" Grid.Row="0" HorizontalAlignment="Stretch" />
<RibbonButton x:Name="cmdSaveImage" Background="#FFFFC500" Label="Save" Click="cmdSaveImage_Click" Margin="10,10,10,0" Grid.Row="1" HorizontalAlignment="Stretch" />
</Grid>
</RibbonGroup>
</RibbonTab>
</Ribbon>
</Grid>
</Window>

我也试过添加

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

在行定义之后。

最佳答案

我不确定为什么 Horizo​​ntalAlignmentHorizo​​ntalContentAlignment 属性没有按预期执行 - 可能是功能区控件模板中的错误。

无论如何,有一个解决方法:您可以将 RibbonGroupGrid 绑定(bind)到 RibbonTab 的 ActualWidth 属性.您可能需要使用转换器来使用偏移量微调这些值,但总而言之,它可以解决问题:

<Ribbon VerticalAlignment="Top">
<RibbonTab x:Name="tab" Header="Home" Height="88" VerticalAlignment="Top">
<RibbonGroup Width="{Binding ElementName=tab, Path=ActualWidth}" Header="Save/Load" Height="88" Margin="0" VerticalAlignment="Top">
<Grid Width="{Binding ElementName=tab, Path=ActualWidth}" HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<RibbonButton x:Name="cmdLoadImage" Background="#FFFFC500" Label="Load" Click="cmdLoadImage_Click" Margin="10,10,10,0" Grid.Row="0" HorizontalAlignment="Stretch" />
<RibbonButton x:Name="cmdSaveImage" Background="#FFFFC500" Label="Save" Click="cmdSaveImage_Click" Margin="10,10,10,0" Grid.Row="1" HorizontalAlignment="Stretch" />
</Grid>
</RibbonGroup>
</RibbonTab>
</Ribbon>

关于wpf - 在 RibbonGroup 内水平拉伸(stretch) WPF 网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13430053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com