2015-05-24 110 views
0

我想有一個文本框出現在我的遊戲的贏家結束。我在文本屬性上使用了一個觸發器來完成此操作,該屬性將可見性設置爲空時處於摺疊狀態。接下來,我嘗試在此文本框中添加邊框。當我的文本框,然而崩潰(所以當遊戲仍在繼續),文本框是無形前,但邊界已經顯示在屏幕上的一個小黑匣子。隱藏邊框當文本框爲空

有誰知道我可以隱藏邊框,直到它包含的文本框是不是空的?

在此先感謝。

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

回答

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

這解決了它,非常感謝! –