c# - 如何设置多个viewbox最大的尺寸?

标签 c# wpf

我正在尝试显示四个带有边框和 TextBlock 的 View 框。问题是 TextBlock 的大小不同。我想改变盒子的大小,所以我不能得到 4 个相同大小的盒子。我能得到一些帮助吗?

我已经试过了 how to make texts in two Viewboxes the same size?但它没有用,我的盒子几乎消失了

<Viewbox x:Name="FirstBox" Grid.Row="0">
    <StackPanel Orientation="Horizontal">
        <Border Background="red">
            <StackPanel Orientation="Horizontal">
                 <TextBlock Text="short text"/>
                 <TextBlock Text="More text" />
            </StackPanel>
        </Border>
    </StackPanel>
</Viewbox>

(This box four times with different text)
private void ChangeBoxSize()
{
    double first = FirstBox.ActualWidth;
    double second = SecondBox.ActualWidth;
    double third = ThirdBox.ActualWidth;
    double fourth = FourthBox.ActualWidth;
    double longest = first;

    if (second > longest)
    longest = second;
    if (third > longest)
        longest = third;
    if (fourth > longest)
        longest = fourth;
    FirstBox.MinWidth = longest;
    SecondBox.MinWidth = longest;
    ThirdBox.MinWidth = longest;
    FourthBox.MinWidth = longest;
}

我原以为最长的盒子会将其宽度分配给其他盒子。其实什么都没发生

最佳答案

我只需要删除 View 框,放置一个网格并将文本对齐方式设置为一侧。感谢@taktak 的网格

关于c# - 如何设置多个viewbox最大的尺寸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57271976/

相关文章:

c# - 为什么在 json 字符串中添加 [ ] 有效,以及为什么它之前不起作用

c# - 基本造型。母版页右侧的导航栏

wpf - XAML ColumnDefinition 中 *(星号)的含义是什么?

.net - wpf 绑定(bind)到索引器

c# - 使用 Prism 设置数据上下文

c# - 我可以在 1 个应用程序中拥有同一个 UserControl 的多个实例吗?

c# - 在 C# List 的下一个列表项中根据 StartDate 设置 EndDate

c# - 计时器以秒为单位精确计时

C#:Socket.ReceiveAsync 和部分接收

c# - 如何将单个数据网格行 FontWeights 更改为粗体?