TextBox为空时隐藏边框

时间:2015-05-24 09:52:48

标签: wpf xaml

我试图让我的游戏结束时出现一个文本框与获胜者。我使用text属性上的触发器执行此操作,该触发器将可见性设置为在其为空时折叠。接下来,我尝试在此文本框中添加边框。然而,当我的文本框被折叠时(所以当游戏仍在进行时),文本框像以前一样不可见,但边框已经在屏幕上显示为一个小黑框。

是否有人知道如何隐藏边框,直到它包含的文本框不为空?

提前致谢。

<Border BorderBrush="Black" BorderThickness="2" Canvas.ZIndex="2" Canvas.Left="160" Canvas.Top="225" Background="White"> 
        <TextBlock FontFamily="Helvetica" FontSize="20" FontWeight="Bold"  
                   Text="{Binding WinnerPopup.Value}" Foreground="{Binding WinnerPopup.Value, Converter={StaticResource ownerConverter}}" Padding="15">
            <TextBlock.Style>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <Trigger Property="Text" Value="">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
    </Border>

1 个答案:

答案 0 :(得分:2)

当TextBlock折叠时,您可以使用以下技巧折叠边框:

    <Border Canvas.Left="160"
            Canvas.Top="225"
            Background="White"
            BorderBrush="Black"
            BorderThickness="2"
            Canvas.ZIndex="2"
            Visibility="{Binding Visibility,
                                 ElementName=myTextBlock}">
        <TextBlock x:Name="myTextBlock"
                   FontFamily="Helvetica"
                   FontSize="20"
                   FontWeight="Bold"
                   Foreground="{Binding WinnerPopup.Value,
                                        Converter={StaticResource ownerConverter}}"
                   Padding="15"
                   Text="{Binding WinnerPopup.Value}">
            <TextBlock.Style>
                <Style TargetType="TextBlock">
                    <Style.Triggers>
                        <Trigger Property="Text" Value="">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
    </Border>