根据对象是否具有StackLayout
值,我想要隐藏ListView
IsVisible="false"
PerformedDate
(默认为{null
1}})。
现在,我正在尝试使用DataTriggers
上的StackLayout
使用label
的文字作为对象是否有PerformedDate
的指标:
<Label x:Name="PerformedDateLabel" Text="{Binding PerformedDate}" IsVisible="True"/>
<StackLayout Padding="0, 25, 0, 0" Spacing="0">
<Label Text="{Binding Date, StringFormat='{0:dd}'}" FontSize="Small" HorizontalOptions="Center"/>
<Label Text="{Binding Date, StringFormat='{0:MMM}'}" HorizontalOptions="Center"/>
<StackLayout.Triggers>
<DataTrigger TargetType="StackLayout" Binding="{Binding Source={x:Reference PerformedDateLabel}, Path=Text}" Value="">
<Setter Property="IsVisible" Value="False"/>
</DataTrigger>
</StackLayout.Triggers>
</StackLayout>
当StackLayout
存在时,它不会隐藏PerformedDate
。
有什么想法吗?
我也尝试了Path=Text.Length
Value="0"
方法。
答案 0 :(得分:2)
您可以使用其他属性HasPerformedDate
<强> C#强>
public DateTime? PerformedDate
{
get { return _performedDate; }
set
{
_performedDate = value;
OnPropertyChanged();
OnPropertyChanged(nameof(HasPerformedDate));
}
}
public bool HasPerformedDate => PerformedDate.HasValue;
<强>的Xaml 强>
<Label x:Name="PerformedDateLabel" Text="{Binding PerformedDate}" IsVisible="True"/>
<StackLayout Padding="0, 25, 0, 0" Spacing="0" IsVisible="{Binding HasPerformedDate}">
<Label Text="{Binding PerformedDate, StringFormat='{0:dd}'}" FontSize="Small" HorizontalOptions="Center"/>
<Label Text="{Binding PerformedDate, StringFormat='{0:MMM}'}" HorizontalOptions="Center"/>
</StackLayout>