我在 Listview 中有两个堆栈布局。我想根据情况一次显示每个。此处有一个名为 Complete 的值。如果为False,则应显示实验室结果。如果为真,则应显示“文档列表”。这行不通。如何实现?
<StackLayout x:Name="LabLayout" IsVisible="False" Orientation="Vertical" HorizontalOptions="Start" Spacing="0" Margin="0,-6,0,0">
<StackLayout.Triggers>
<DataTrigger TargetType="StackLayout" Binding="{Binding Completed}" Value="True">
<Setter Property="StackLayout.IsVisible" Value="False"/>
</DataTrigger>
<DataTrigger TargetType="StackLayout" Binding="{Binding Completed}" Value="False">
<Setter Property="StackLayout.IsVisible" Value="True"/>
</DataTrigger>
</StackLayout.Triggers>
<Label Text="{Binding Title}" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize17}"/>
<Label Text="{Binding Author}" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding LabItemStatus }" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
<Label Text="{Binding Progress}" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
</StackLayout>
</StackLayout>
<StackLayout x:Name="DocumentLayout" IsVisible="False" Orientation="Vertical" HorizontalOptions="Start" Spacing="0" Margin="0,-6,0,0">
<StackLayout.Triggers>
<DataTrigger TargetType="StackLayout" Binding="{Binding Completed}" Value="False">
<Setter Property="StackLayout.IsVisible" Value="False"/>
</DataTrigger>
<DataTrigger TargetType="StackLayout" Binding="{Binding Completed}" Value="True">
<Setter Property="StackLayout.IsVisible" Value="True"/>
</DataTrigger>
</StackLayout.Triggers>
<Label Text="{Binding Title}" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize17}"/>
<Label Text="{Binding DateTimeString}" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Department }" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize13}"/>
<Label Text="||" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize13}"/>
<Label Text="{Binding Author}" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize13}"/>
</StackLayout>
</StackLayout>
答案 0 :(得分:0)
对每个布局使用单独的绑定。喜欢
<StackLayout x:Name="LabLayout" IsVisible="{Binding LabLayoutVisibility}" Orientation="Vertical" HorizontalOptions="Start" Spacing="0" Margin="0,-6,0,0">
<Label Text="{Binding Title}" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize17}"/>
<Label Text="{Binding Author}" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding LabItemStatus }" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
<Label Text="{Binding Progress}" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
</StackLayout>
</StackLayout>
<StackLayout x:Name="DocumentLayout" IsVisible="{Binding DocumentLayoutVisibility}" Orientation="Vertical" HorizontalOptions="Start" Spacing="0" Margin="0,-6,0,0">
<Label Text="{Binding Title}" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize17}"/>
<Label Text="{Binding DateTimeString}" TextColor="{StaticResource QuateneryLightColor}" FontSize="{StaticResource FontSize13}"/>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Department }" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize13}"/>
<Label Text="||" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize13}"/>
<Label Text="{Binding Author}" TextColor="{StaticResource DarkColor}" FontSize="{StaticResource FontSize13}"/>
</StackLayout>
</StackLayout>
答案 1 :(得分:0)
IValueConverter
用于在不同类型之间转换值,在这里您可以创建一个与Completed
相反的新变量,并将其绑定到StackLayout.IsVisible
private bool completed;
public bool Completed {
get
{
return completed;
}
set {
completed = value;
UnCompleted= !completed;
OnPropertyChanged("Completed");
}
}
public bool UnCompleted
{
get;
set;
}
<StackLayout IsVisible="{Binding UnCompleted}">