WPF Expander 在 Canvas 中不会向左扩展 [英] WPF Expander won't expand left when inside Canvas

查看:29
本文介绍了WPF Expander 在 Canvas 中不会向左扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a grid with 4 columns. In the first column is a Canvas with a ZIndex of 99 and inside that is an expander. The expand direction is set to RIGHT. When I click on the header, the expander expands OVER TOP of column 2...which is exactly what I want. I'm trying to replicate this (only the opposite direction) inside column 4, so that when expanded, it will show over column 3. Even though I've marked the ExpandDirection of the second expander to "Left", it still expands to the right, and off the screen.

这是工作扩展器:

<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>

推荐答案

不要使用画布.

尝试类似的方法:

<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>

这篇关于WPF Expander 在 Canvas 中不会向左扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆