如何在wpf中隐藏面板后面的项目

时间:2015-06-02 06:12:28

标签: c# .net wpf xaml visual-studio-2012

我使用以下代码进行控制显示

<Window x:Class="WpfApplication29.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid >
        <Border Margin="100" BorderThickness="3" BorderBrush="Black">
        <Canvas>
                <Label Content="This is test" FontSize="129" Width="400" Height="200"/>
            </Canvas>
        </Border>
    </Grid>
</Window>

enter image description here

如果size大于parent controlmargin is negative

,我想将其显示为从下方剪切的第二个

2 个答案:

答案 0 :(得分:4)

您只需要为边框使用ClipToBounds="True"属性

 <Grid >
        <Border Margin="100" BorderThickness="3" BorderBrush="Black" ClipToBounds="True">
            <Canvas  >
                <Label Content="This is test" FontSize="129" Width="400" Height="200"/>
            </Canvas>
        </Border>
    </Grid>

答案 1 :(得分:3)

只需使用Canvas的ClipToBounds属性为True

UITextField

enter image description here

<Window x:Class="WpfApplication29.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid >
    <Border Margin="100" BorderThickness="3" BorderBrush="Black">
    <Canvas ClipToBounds="True">
            <Label Content="This is test" FontSize="129" Width="400" Height="200"/>
        </Canvas>
    </Border>
</Grid>