wpf - 非正方形布局

标签 wpf panel

我正在尝试在 wpf 中进行某种布局,最好的解释方式是向您展示:

这是现在的样子:

enter image description here

它应该是这样的:

enter image description here

有没有人知道如何在 wpf 中完成这个?边框需要与图片中的完全一样。

谢谢。

最佳答案

如果这些是网格,您可以使用两个 Border 将其 Width 设置为 CornerRadius 并将其高度绑定(bind)到 来伪造 99.9% >ActualHeight 右上面板:

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="3*" />
    <ColumnDefinition Width="2*" />
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="9*" />
  </Grid.RowDefinitions>
  <Border Background="Red" Grid.RowSpan="2" CornerRadius="5" Margin="2"/>
  <Border x:Name="TopRight" Background="Red" Grid.Column="1"
          CornerRadius="5" Margin="2"/>
  <Border Background="Yellow" Width="5"
          Height="{Binding ActualHeight, ElementName=TopRight}"
          HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,2,0,2"/>
  <Border Background="Yellow" Width="5" HorizontalAlignment="Left"
          Height="{Binding ActualHeight, ElementName=TopRight}"
          VerticalAlignment="Top" Grid.Column="1" Margin="0,2,2,0"/>
  <Border Background="Green" Grid.Column="1" Grid.Row="1"
          CornerRadius="5" Margin="2"/>
</Grid>

此处的颜色仅作为叠加层的示例。

关于wpf - 非正方形布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10947091/

相关文章:

c# - WPF MVVM 代码背后的最佳实践

.net - 在数据网格中水平滚动时绑定(bind)警告

c# - Excel 应用程序单例 - 仅使用一个 Excel 应用程序实例而不退出的可能威胁?

java - 如何创建滑动面板

java - 创建透明面板

wpf - 如何更改 TextBlock 中的行距

wpf - 组合框丢失 SelectedIndex

c# - 表格 : Enabled/Disable all controls in a container (panel)

java - 使用 FlowLayout 创建框架

c# - 如何在 c#.Net 中创建透明面板