Использование триггеров для выбора между двумя макетами стека при условии, что формы Xamarin не работают - PullRequest
0 голосов
/ 05 июня 2019

У меня есть два макета стека внутри 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>

Ответы [ 2 ]

0 голосов
/ 05 июня 2019

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}">
0 голосов
/ 05 июня 2019

Используйте отдельную привязку для каждого макета. как

<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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...