Visibility.Collapsed仍然显示内容

时间:2011-09-07 15:12:42

标签: silverlight xaml windows-phone-7

我有一个自定义控件,我最初设置为像这样折叠

<local:SpriteButton Content="Why?" x:Name="showReason" Click="showReason_Click" Margin="418,12,12,656" Visibility="Collapsed" />

但是当我运行应用程序时,内容在这种情况下是“为什么?”显示在那里,但整个UserControl包括它的内容需要隐藏。

为什么?

Sprite Button类看起来像这样

<Button x:Class="AppNameSpace.MyControls.SpriteButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:AppNameSpace.MyControls"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="White"
    Loaded="Button_Loaded"
    HorizontalAlignment="Center" VerticalAlignment="Center"
    MouseLeftButtonDown="Button_MouseLeftButtonDown"
    MouseLeave="Button_MouseLeave"
    ClickMode="Hover"
>

    <Button.Resources>
        <Style x:Key="PhoneButtonCheckBoxBase" TargetType="Button">
            <Setter Property="Background" Value="{StaticResource PhoneRadioCheckBoxBrush}"/>
            <Setter Property="BorderBrush" Value="{StaticResource PhoneRadioCheckBoxBrush}"/>
            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
            <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <!--Setter Property="Padding" Value="-10"/-->
        </Style>
        <Style x:Key="RectButton" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Background="Transparent">
                            <Grid>
                                <local:spriteView HorizontalAlignment="Center" Sprite="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=currentSprite}" />

                                <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" />
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Button.Resources>


    <Button.Style>
        <StaticResource ResourceKey="RectButton"/>
    </Button.Style>

</Button>

SpriteView是我正在使用的另一个自定义控件,但隐藏正确,它下面的内容控件始终显示。

1 个答案:

答案 0 :(得分:0)

这个问题需要更多代码来表明你的意思......

如果你试图隐藏子控件或容器,它也需要与父控件一起隐藏。

这至少听起来像你的要求,请发布更多信息,以便我们为您提供帮助。 :)