如何转到另一个 xaml 页面 xamarin.form FlowListView



我在xamarin表单中创建了FlowListView.FlowLoadTemplate。 单击FlowItemTappedCommand时,转到另一个页面或导航到其他页面。

FlowListView xaml:

<StackLayout Padding="10">
<flv:FlowListView FlowColumnCount="2"  
x:Name="FlowListView"
SeparatorVisibility="Default"   
HasUnevenRows="True"                  
FlowTappedBackgroundColor="Red" FlowIsLoadingInfiniteEnabled="True"
FlowItemTappedCommand="{Binding ItemTappedCommand}"   
FlowItemsSource="{Binding Items}">
<flv:FlowListView.FlowLoadingTemplate>
<DataTemplate>
<ViewCell>
<Label
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
TextColor="Black"
Text="Loading..."
></Label>
</ViewCell>
</DataTemplate>
</flv:FlowListView.FlowLoadingTemplate>
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate >
<Grid Padding="5">
<BoxView Color="#121E22" Opacity="0.8" CornerRadius="6" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Row="0">
</BoxView>
<StackLayout Padding="5" Grid.Row="0">
<ff:CachedImage
HeightRequest="70" WidthRequest="70" Aspect="AspectFill" 
HorizontalOptions="Center" VerticalOptions="Center"
DownsampleWidth="70" DownsampleUseDipUnits="true"
Source ="{Binding Icon}" DownsampleToViewSize="True"
LoadingPlaceholder="Spinner.png" 
ErrorPlaceholder= "ErrorImage"
CacheDuration= "50"
RetryCount= "3"
RetryDelay= "600"
>
</ff:CachedImage>
<Label Text="{Binding Title}" TextColor="White" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Center"/>
</StackLayout>
</Grid>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
</StackLayout>

流列表绑定类/cs 文件

public class ItemPageModel: BindableObject
{
private ItemsPage itemsPage;
public ItemPageModel(ItemsPage itemsPage)
{
this.itemsPage = itemsPage;
AddItems();
}
private void AddItems()
{
Items.Add(new DashboardItemList { Title = "Junction List", Icon = "baseline_view_list_white_48.png", Id = ManuItemList.JunctionList });
Items.Add(new DashboardItemList { Title = "Live Monitoring", Icon = "baseline_visibility_white_48.png" , Id = ManuItemList.LiveMonitoring });
Items.Add(new DashboardItemList { Title = "Specification", Icon = "baseline_details_white_36.png" , Id = ManuItemList.Specification });
Items.Add(new DashboardItemList { Title = "Time Setting", Icon = "baseline_settings_applications_white_48.png", Id = ManuItemList.TimeSetting });
Items.Add(new DashboardItemList { Title = "Fault Logs", Icon = "baseline_add_alert_white_48.png" , Id = ManuItemList.FaultLogs });
Items.Add(new DashboardItemList { Title = "Linking Status", Icon = "baseline_link_white_48.png" , Id = ManuItemList.LinkingStatus });
Items.Add(new DashboardItemList { Title = "Linking Status", Icon = "https://farm9.staticflickr.com/8625/15806486058_7005d77438.jpg" });
}
private ObservableCollection<DashboardItemList> _items = new ObservableCollection<DashboardItemList>();
public ObservableCollection<DashboardItemList> Items
{
get
{
return _items;
}
set
{
if (_items != value)
{
_items = value;
OnPropertyChanged(nameof(Items));
}
}
}
public Command ItemTappedCommand
{
get
{
return new Command(async (sender) =>
{
var Item = sender as DashboardItemList;
await Navigation.PushAsync(new JunctionList());

});
}
}
}

}

我尝试了很多方法去另一个,但我得到了异常或应用程序崩溃

这是我单击选项卡时转到的另一个页面

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="MITSAPP.Views.JunctionList">
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand" 
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage.Content>

您需要在 App.xaml.cs 中设置带有导航页的主页。

MainPage = new NavigationPage(new ItemPage());

您还必须使用导航页面添加详细信息页面,如下所示,

<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<pages:YourDetailPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>

然后,您可以从详细信息页面导航到任何页面。

我在我身边尝试您的代码,但是当点击 FlowListView 项目时我可以导航到另一个页面,我没有问题,这是我的示例,您可以下载进行测试。

https://github.com/CherryBu/Sample1

我看到你说你从MasterDetailedPage导航,如果你仍然有问题,你能在github上传你的样本吗,我会下载你的样本进行测试。

相关内容

  • 没有找到相关文章

最新更新