XAML Xamarin窗体如何在单击列表视图上的菜单时打开弹出窗口

qxsslcnc  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(173)

我有一个XAML页面,其中包含菜单的ListView,我正在尝试将注销链接为按钮以显示RadPopup。此Popup没有MVVM
我是新人,你别怪我......
这是XAML上的ListView

<ListView x:Name="listview" x:FieldModifier="public" 
                  BackgroundColor="{StaticResource BlueDark}"
                  SeparatorVisibility="Default" 
                  SeparatorColor="White" 
                  SelectionMode="Single"
                  HasUnevenRows="False"
                  ios:ListView.SeparatorStyle="FullWidth">

            <ListView.ItemsSource>
                <x:Array Type="{x:Type local:MenuItem}">

                    <local:MenuItem  Title="{x:Static lang:AppResources.MenuHome}"           TargetPage="{x:Type local:AlarmsListPage}"/>
                    <local:MenuItem  Title="{x:Static lang:AppResources.MenuSitesAndAssets}" TargetPage="{x:Type local:AlarmsListPage}"/>
                    <local:MenuItem  Title="{x:Static lang:AppResources.MenuUserProfile}"    TargetPage="{x:Type local:AlarmsListPage}"/>
                    <local:MenuItem  Title="{x:Static lang:AppResources.MenuFeedback}"       TargetPage="{x:Type local:AlarmsListPage}"/>
                    <local:MenuItem  Title="{x:Static lang:AppResources.MenuLogout}"        TargetPage="{x:Type local:AlarmsListPage} "/>
                </x:Array>
            </ListView.ItemsSource>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="33"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Grid.ColumnSpan="3"
                                   Text="{Binding Title}" TextColor="white" Padding="15,0,0,0"
                                   VerticalTextAlignment="Center"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

我还为PopupView XAML创建了一个内容页

<ContentPage.Content>
        <Button Clicked="LogoutPopup">
            <telerikPrimitives:RadPopup.Popup>
                <telerikPrimitives:RadPopup x:Name="Popup" Placement="Center" OutsideBackgroundColor="WhiteSmoke"  IsModal="False">
                    <telerikPrimitives:RadBorder CornerRadius="10" BackgroundColor="{StaticResource BlueDark}">
                        <Grid Padding="25">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100"/>
                                <ColumnDefinition Width="100"/>
                            </Grid.ColumnDefinitions>
                            <StackLayout Margin="12" Padding="24" Spacing="24" BackgroundColor="{StaticResource BlueDark}" HorizontalOptions="Center" VerticalOptions="Center">
                                <StackLayout>
                                    <Label Grid.Column="0"  Grid.Row="0" Grid.ColumnSpan="2" TextColor="{StaticResource White}" HorizontalTextAlignment="Center" 
                                     Text="Are you sure you want to log out? You will no longer receive alarm notifications." />
                                </StackLayout>
                                <Button Grid.Column="0" Grid.Row="1" BackgroundColor="Transparent" TextColor="{StaticResource White}" Text="Yes"/>
                                <Button Grid.Column="1" Grid.Row="1" BackgroundColor="Transparent" TextColor="{StaticResource White}" Text="No"/>
                            </StackLayout>
                        </Grid>
                    </telerikPrimitives:RadBorder>
                </telerikPrimitives:RadPopup>
            </telerikPrimitives:RadPopup.Popup>
        </Button>
    </ContentPage.Content>
</ContentPage>

我正在尝试将PopupView绑定到Logout ListView。有人能帮我吗?

r7xajy2e

r7xajy2e1#

从我的Angular 来看,按钮是不必要的。你可以使用列表视图的ItemSelected事件来创建它。
在xaml中,只需添加listview_ItemTapped事件处理程序:

<StackLayout>
<ListView x:Name="listview" x:FieldModifier="public" 
              ItemTapped="listview_ItemTapped"  // add this line
              BackgroundColor="AliceBlue"
              SeparatorVisibility="Default" 
              SeparatorColor="White" 
              SelectionMode="Single"
              HasUnevenRows="False"
              >
...
...

</ListView>
// you could just put your popup after listview
<telerikPrimitives:RadPopup.Popup>
    <telerikPrimitives:RadPopup x:Name="Popup" ...

...

</telerikPrimitives:RadPopup.Popup>
</StackLayout>

在.cs文件中实现它:

void listview_ItemTapped(System.Object sender, Xamarin.Forms.ItemTappedEventArgs e)
    {
        // popup page here
        Popup.IsOpen = true;
    }

希望对你有用。

相关问题