0

List EDocuments имеет модель EDocument. List EDocuments часть основной ViewModel. Когда я вычитываю лист, мне надо скрыть некоторые данные согласно бизнес логике, для примера, вот часть которую мне надо скрыть:

StackLayout Orientation="Horizontal" Padding="15, 15, 0, 0" IsVisible="{Binding MainViewModel.NewDocumentsExists}"  

Поле NewDocumentsExists часть основной ViewModel, не EDocument. Как мне обратится к основной моделе? Я себе представлял это так MainViewModel.NewDocumentsExists

Main:

<StackLayout  BindableLayout.ItemsSource="{Binding EDocuments}">
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <Frame CornerRadius="5"  OutlineColor="#c3c3c3" BackgroundColor="#F2FFFFE0">
                <StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand">
                    <StackLayout Orientation="Horizontal">
                        <Label Style="{StaticResource LabelTitleFontSize}" Text="Номер документа:" ></Label>
                        <Label Style="{StaticResource LabelFontSize}" Text="{Binding DocumentNum}"></Label>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Label Style="{StaticResource LabelTitleFontSize}" Text="Точка вивантаження:" ></Label>
                        <Label Style="{StaticResource LabelFontSize}" Text="{Binding UnloadPoint}"></Label>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Label Style="{StaticResource LabelTitleFontSize}" Text="Кількість місць:" ></Label>
                        <Label Style="{StaticResource LabelFontSize}" Text="{Binding PlacesTotal}"></Label>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Label Style="{StaticResource LabelTitleFontSize}" Text="Загальна вага:" ></Label>
                        <Label Style="{StaticResource LabelFontSize}" Text="{Binding WeightTotal}"></Label>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Label Style="{StaticResource LabelTitleFontSize}" Text="Статус:" ></Label>
                        <Label Style="{StaticResource LabelTitleFontSize}" TextColor="Red" Text="{Binding EDocState.StateName}"></Label>
                    </StackLayout>
                    <StackLayout Orientation="Horizontal">
                        <Line BackgroundColor="Black" HeightRequest="1" />
                        <Label Text="Перелік товару:" TextColor="Black" FontSize="22"/>
                    </StackLayout>
                    <StackLayout  BindableLayout.ItemsSource="{Binding Specifications}">
                        <BindableLayout.ItemTemplate>
                            <DataTemplate>
                                <Frame CornerRadius="5" OutlineColor="#c3c3c3" BackgroundColor="White">
                                    <StackLayout>
                                        <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                            <Label Style="{StaticResource LabelTitleFontSize}" Text="Найменування:"/>
                                            <Label Style="{StaticResource LabelFontSize}" Text="{Binding Name}"/>
                                        </StackLayout>
                                    &lt;StackLayout Orientation=&quot;Horizontal&quot; HorizontalOptions=&quot;FillAndExpand&quot;&gt;
                                        &lt;Label Style=&quot;{StaticResource LabelTitleFontSize}&quot; Text=&quot;Тип:&quot;/&gt;
                                        &lt;Label Style=&quot;{StaticResource LabelFontSize}&quot; Text=&quot;{Binding TypeOfPackaging}&quot;/&gt;
                                    &lt;/StackLayout&gt;

                                    &lt;StackLayout Orientation=&quot;Horizontal&quot; HorizontalOptions=&quot;FillAndExpand&quot;&gt;
                                        &lt;Label Style=&quot;{StaticResource LabelTitleFontSize}&quot; Text=&quot;Вага:&quot;/&gt;
                                        &lt;Label Style=&quot;{StaticResource LabelFontSize}&quot; Text=&quot;{Binding GrossWeight}&quot;/&gt;
                                    &lt;/StackLayout&gt;

                                    &lt;StackLayout Orientation=&quot;Horizontal&quot; HorizontalOptions=&quot;FillAndExpand&quot;&gt;
                                        &lt;Label Style=&quot;{StaticResource LabelTitleFontSize}&quot; Text=&quot;Кількість місць:&quot;/&gt;
                                        &lt;Label Style=&quot;{StaticResource LabelFontSize}&quot; Text=&quot;{Binding NumberOfSeats}&quot;/&gt;
                                    &lt;/StackLayout&gt;
                                &lt;/StackLayout&gt;
                            &lt;/Frame&gt;
                        &lt;/DataTemplate&gt;
                    &lt;/BindableLayout.ItemTemplate&gt;
                &lt;/StackLayout&gt;
                &lt;StackLayout Orientation=&quot;Horizontal&quot; Padding=&quot;15, 15, 0, 0&quot; IsVisible=&quot;{Binding **NewDocumentsExists**}&quot; IsEnabled=&quot;{Binding NewDocumentsExists}&quot;&gt;
                    &lt;Label Style=&quot;{StaticResource LabelTitleFontSize}&quot; Text=&quot;Вибрати:&quot; Margin=&quot;0, 0, 20, 0&quot; /&gt;
                    &lt;Switch Scale=&quot;1.5&quot; IsToggled=&quot;{Binding NewDocumentsExists}&quot;  OnColor=&quot;LightGray&quot; ThumbColor=&quot;{Binding SwitchColor}&quot; /&gt;
                &lt;/StackLayout&gt;
            &lt;/StackLayout&gt;
        &lt;/Frame&gt;
    &lt;/DataTemplate&gt;
&lt;/BindableLayout.ItemTemplate&gt;

</StackLayout>

  • 1
    Не к полю, а свойству (public ... SomeProperty {get;set;} - это свойство). А так, https://ru.stackoverflow.com/a/724594/220553 – EvgeniyZ Jun 24 '22 at 12:02
  • @EvgeniyZ да все верно, свойство, спасибо. Ваш ответ подошел, все работает. – Winteriscoming Jun 24 '22 at 12:34
  • Если ответ подошел, то значит это дубликат, на который надо закрыть вопрос. – EvgeniyZ Jun 24 '22 at 12:40

1 Answers1

0

Добавлю мой результат в качестве примера.

<StackLayout Orientation="Horizontal" Padding="15, 15, 0, 0" IsVisible="{Binding Source={RelativeSource AncestorType={x:Type view:EdocumentsListViewModel}}, Path=NewDocumentsExists}">
    <Label Style="{StaticResource LabelTitleFontSize}" Text="Вибрати:" Margin="0, 0, 20, 0" />
    <Switch Scale="1.5" IsToggled="{Binding IsChecked}"  OnColor="LightGray" ThumbColor="{Binding SwitchColor}" />
</StackLayout>  

Основу взял здесь.