我有一个最初设置为折叠的自定义控件,如下所示
<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是我正在使用的另一个自定义控件,但它隐藏正确,它下面的correct控件总是显示出来。
发布于 2011-09-08 05:11:32
这个问题需要更多的代码来显示你的意思......
如果您试图隐藏一个子控件或容器,它也需要与父控件一起隐藏。
这至少听起来像是你的要求,请多发一些,这样我们就可以帮助你了。:)
https://stackoverflow.com/questions/7336248
复制相似问题