Xamarin MasterPage - показать / скрыть разделительную строку в меню - PullRequest
0 голосов
/ 23 января 2019

Как мне показать / скрыть разделительную строку в меню из MasterPage? На данный момент все линии, кажется, включены, но я не знаю, откуда они берутся. Я хочу отключить все строки, кроме линии между «Slaap» и «Persoonlijke gegevens». На этой картинке видно, что есть только две линии, но на самом деле вы можете ясно видеть их все.

https://i.stack.imgur.com/6EIrA.jpg

MasterPage.xaml

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:TimeToSport.Views"
         xmlns:local1="clr-namespace:TimeToSport.Views"
         x:Class="TimeToSport.Views.Main.MasterPage"
         Padding="0,0,0,0" Title="Time To Sport">
<StackLayout>
    <Image Source="HeaderBackground.png" Margin="0,0,0,15"/>
    <ListView x:Name="listView" x:FieldModifier="public">
        <ListView.ItemsSource>
            <x:Array Type="{x:Type local:MasterPageItem}">
                <local1:MasterPageItem Title="Home" IconSource="contacts.png" TargetType="{x:Type local:ItemsPage}" />
                <local1:MasterPageItem Title="Sport" IconSource="contacts.png" TargetType="{x:Type local:SportPage}" />
                <local1:MasterPageItem Title="Voeding" IconSource="reminders.png" TargetType="{x:Type local:VoedingPage}" />
                <local1:MasterPageItem Title="Slaap" IconSource="todo.png" TargetType="{x:Type local:SlaapPage}" />
                <local1:MasterPageItem Title="Persoonlijke Gegevens" IconSource="todo.png" TargetType="{x:Type local:GegevensGewichtDoel}"/>
            </x:Array>
        </ListView.ItemsSource>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid Padding="5,10">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding IconSource}" />
                        <Label Grid.Column="1" Text="{Binding Title}" FontSize="17" />
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackLayout>
</ContentPage>

1 Ответ

0 голосов
/ 23 января 2019

Во-первых, ваш Listview должен иметь SeparatorVisibility=None,

В вашем local: MasterPageItem добавить новое свойство IsSeparator, чтобы определить, какой элемент будет разделителем

Затем в вашемlistview

<ListView x:Name="listView" SeparatorVisibility="None" x:FieldModifier="public">
        <ListView.ItemsSource>
            <x:Array Type="{x:Type local:MasterPageItem}">
                <local1:MasterPageItem Title="Home" IconSource="contacts.png" TargetType="{x:Type local:ItemsPage}" />
                <local1:MasterPageItem Title="Sport" IconSource="contacts.png" TargetType="{x:Type local:SportPage}" />
                <local1:MasterPageItem Title="Voeding" IconSource="reminders.png" TargetType="{x:Type local:VoedingPage}" />
                <local1:MasterPageItem IsSeparator="true" Title="Slaap" IconSource="todo.png" TargetType="{x:Type local:SlaapPage}" />
                <local1:MasterPageItem Title="Persoonlijke Gegevens" IconSource="todo.png" TargetType="{x:Type local:GegevensGewichtDoel}"/>
            </x:Array>
        </ListView.ItemsSource>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid Padding="5,10">
                        <Grid.RowDefinitions>
                            <RowDefinition Height ="*"/>
                            <RowDefinition Height ="1"/>
                        <Grid.RowDefinitions/>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="30"/>
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding IconSource}" />
                        <Label Grid.Column="1" Text="{Binding Title}" FontSize="17" />

                        <BoxView Grid.Row="1" Grid.ColumnSpan="2" HeightRequest="1" Color="Red" IsVisible="{Binding IsSeparator}">
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...