Xamarin窗体如何打开一个弹出窗口,当你点击一个菜单在列表视图



我有一个XAML页面,包含菜单的ListView,我试图将Logout链接为显示RadPopup的按钮。这个弹出窗口没有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创建了一个contentpageXAML

<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。有人能帮我一下吗?

从我的角度来看,按钮是不必要的。你可以使用listview的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;
}

希望它对你有用。

相关内容

  • 没有找到相关文章

最新更新