-1

我想在 wpf 中 Text 属性为空或为空时更改 TextBlock 的可见性,我们可以轻松地做到这一点:

<Style TargetType = "TextBlock"> 
         <Setter Property = "Visibility" Value = "Visibile" /> 
         <Style.Triggers> 
            <Trigger Property = "Text" Value = ""> 
               <Setter Property = "Visibility" Value = "Collapsed" /> 
            </Trigger> 
         </Style.Triggers> 
      </Style> 

但是触发器在 uwp 中不可用,我该如何在 uwp 中执行此操作?

4

2 回答 2

0
 <Interactivity:Interaction.Behaviors>
    <Core:DataTriggerBehavior Binding="{Binding Text, ElementName=txt}" ComparisonCondition="Equal" Value="">
        <Core:ChangePropertyAction TargetObject="{Binding ElementName=txt}" PropertyName="Visibility" Value="Collapsed" />
    </Core:DataTriggerBehavior>
 </Interactivity:Interaction.Behaviors>
于 2021-07-29T08:55:01.607 回答
-1

您可以TextBlock在初始化时检查 的内容并相应地更改其可见性,如下所示:

public MainPage()
    {
        this.InitializeComponent();
        if (YourTextBlock.Text == "")
        {
            YourTextBlock.Visibility = Visibility.Collapsed;
        }
        else
        {
            YourTextBlock.Visibility = Visibility.Visible;
        }
    }
于 2021-07-29T07:18:27.647 回答