1

在此处输入图像描述

在此处输入图像描述

我设计了如果用户单击 listviewitem,sidemenu 加载并显示一些数据

但我有一些问题是侧面菜单没有隐藏

你可以看到上面的第一个屏幕截图侧面菜单没有隐藏,如果我单击列表视图项目,侧面菜单更改第二个屏幕截图

<ContentPage.Content>
       <xct:SideMenuView State="{Binding SideMenuState}" xct:SideMenuView.MenuGestureEnabled="False" xct:SideMenuView.Position="MainView"> 
        <ListView x:Name="lvMonitoring" SeparatorVisibility="None" HasUnevenRows="True" Margin="0, 5, 0, 0"
              SelectedItem="{Binding SelectedChannel}" ItemsSource="{Binding TargetChannelList}">
            <ListView.ItemTemplate>
                <DataTemplate x:DataType="model:Channel">
                    <ViewCell>
                        <Frame CornerRadius="5" Margin="4" HasShadow="True" Padding="0">
                            <Grid BackgroundColor="{Binding Status, Converter={StaticResource Key=StatusToColorConverter}}" HeightRequest="60">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="0.6*"/>
                                    <ColumnDefinition Width="0.4*"/>
                                </Grid.ColumnDefinitions>
                                <Grid Grid.Column="0" HorizontalOptions="Start" VerticalOptions="Center" Margin="10, 0, 0, 0">
                                    <StackLayout>
                                        <Label Text="{Binding DisplayName}" Style="{StaticResource DefaultLabel}"/>
                                    </StackLayout>
                                </Grid>
                                <Grid Grid.Column="1" Margin="0, 0, 15, 0" HorizontalOptions="End" VerticalOptions="Center">
                                    <Label Text="{Binding Status, Converter={StaticResource Key=StatusToTextConverter}}" />
                                </Grid>
                            </Grid>
                        </Frame>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
        
        <xct:TabView  xct:SideMenuView.Position="RightMenu"
            xct:SideMenuView.MenuWidthPercentage=".7">
            <xct:TabViewItem Text="">
                <Button Text=""/>
            </xct:TabViewItem>
            <xct:TabViewItem Text="">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="0.1*"/>
                        <RowDefinition Height="0.9*"/>
                    </Grid.RowDefinitions>
                    <Grid Grid.Row="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.4*"/>
                            <ColumnDefinition Width="0.4*"/>
                            <ColumnDefinition Width="0.2*"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                    <ListView Grid.Row="1" ItemsSource="{Binding NotificationHistoryList}">
                        <ListView.ItemTemplate>
                            <DataTemplate x:DataType="model:NotificationHistory">
                                <ViewCell>
                                    <Frame HasShadow="True" CornerRadius="4" Margin="4" Padding="0">
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="0.4*"/>
                                                <ColumnDefinition Width="0.4*"/>
                                                <ColumnDefinition Width="0.2*"/>
                                            </Grid.ColumnDefinitions>
                                            <Label Grid.Column="0" Text="{Binding DetailLocation}" Style="{StaticResource DefaultLabel}"/>
                                            <Label Grid.Column="1" Text="{Binding NotificationReceivedDateTime, StringFormat='{MM월-dd일 HH시 mm분 ss초}'}" Style="{StaticResource DefaultLabel}"/>
                                            <Label Grid.Column="2" Text="{Binding NotificationStatus, Converter={StaticResource Key=StatusToTextConverter}}" 
                                                   TextColor="{Binding NotificationStatus, Converter={StaticResource Key=StatusToColorConverter}}"/>
                                        </Grid>
                                    </Frame>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>
                </Grid>
            </xct:TabViewItem>
        </xct:TabView>
    </xct:SideMenuView>
</ContentPage.Content>

上面的代码是我的 xaml 代码,我想知道解决方案。如果我忘记设置属性或设置,请告诉我

复制回购:https ://github.com/Sunday5214/XamarinXAMLExamples

4

1 回答 1

0

最好初始化状态属性:

private SideMenuState state = SideMenuState.MainViewShown;

在应用程序启动期间,setter ofSelectedItem被空值命中,因此最好进行检查以避免将State属性设置为SideMenuState.RightMenuShown

    public string SelectedItem
        {
            get => selectedItem;
            set
            {
                SetProperty(ref selectedItem, value);
                if (value != null)
                {
                    State = SideMenuState.RightMenuShown;
                }
            }
        }
于 2021-03-29T19:24:42.533 回答