gpt4 book ai didi

c# - WPF Expander 在 Canvas 内部时不会向左扩展

转载 作者:行者123 更新时间:2023-11-30 16:25:00 26 4
gpt4 key购买 nike

我有一个包含 4 列的网格。第一列是 ZIndex 为 99 的 Canvas ,里面是一个扩展器。扩展方向设置为 RIGHT。当我单击标题时,扩展器扩展到第 2 列的顶部...这正是我想要的。我试图在第 4 列内复制这个(仅相反的方向),以便在展开时显示在第 3 列上。即使我已将第二个扩展器的 ExpandDirection 标记为“左”,它仍然会扩展到右边,然后离开屏幕。

这是工作扩展器:

<Canvas Grid.Column="0" Panel.ZIndex="99" Grid.RowSpan="4" VerticalAlignment="Stretch" Margin="0,5"> 
<Expander ExpandDirection="Right" Style="{DynamicResource OptionsExpanderStyle}" VerticalAlignment="Stretch" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">
<Border BorderBrush="Black" BorderThickness="0,0,2,0">
<Grid Background="White">

</Grid>
</Border>
</Expander>
</Canvas>

这是损坏的扩展器:

<Canvas x:Name="rightCanvas" Panel.ZIndex="99" Grid.RowSpan="4" Grid.Column="3" Margin="0,5">
<Expander ExpandDirection="Left" Style="{DynamicResource OptionsExpanderStyle}" HorizontalAlignment="Right" VerticalAlignment="Stretch" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}">
<Border BorderBrush="Black" BorderThickness="2,0,0,0">
<Grid Background="White" Width="150">

</Grid>
</Border>
</Expander>
</Canvas>

最佳答案

不要使用 Canvas 。

尝试这样的事情:

<Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Background="LightBlue"
TextAlignment="Center" Text="Left Column"/>
<TextBlock Grid.Column="1" Background="LightCoral"
TextAlignment="Center" Text="Right Column"/>
</Grid>
<Expander Background="LightGray" ExpandDirection="Right"
Header="LeftMenu" VerticalAlignment="Top" HorizontalAlignment="Left">
<StackPanel Width="200">
<TextBlock Text="Some menu stuff"/>
<TextBlock Text="Some more"/>
</StackPanel>
</Expander>
<Expander Background="LightGray" ExpandDirection="Left"
Header="RightMenu" VerticalAlignment="Top" HorizontalAlignment="Right">
<StackPanel Width="200" >
<TextBlock Text="Some menu stuff"/>
<TextBlock Text="Some more"/>
</StackPanel>
</Expander>
</Grid>

关于c# - WPF Expander 在 Canvas 内部时不会向左扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10300139/

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