C# Xamarin形成可绑定网格

C# Xamarin形成可绑定网格,c#,mvvm,data-binding,xamarin.forms,C#,Mvvm,Data Binding,Xamarin.forms,一,;我正在开发Xamarin表单应用程序,需要能够绑定到网格。我看到这篇文章: GitHub上的来源: 这正是我所需要的,但是它不响应集合中的更改。我使用的MvvmHelpers适用于所有ListView: 我假设我需要更新TemplatedTableView.cs以响应CollectionChanged事件-我不确定如何执行此操作?您可以将事件添加到ItemSource属性的CollectionChanged事件中 这就是Xamarin表单中ListView的实现方式。您可以在中找到相

一,;我正在开发Xamarin表单应用程序,需要能够绑定到网格。我看到这篇文章:

GitHub上的来源:

这正是我所需要的,但是它不响应集合中的更改。我使用的MvvmHelpers适用于所有ListView:


我假设我需要更新TemplatedTableView.cs以响应CollectionChanged事件-我不确定如何执行此操作?

您可以将事件添加到
ItemSource
属性的
CollectionChanged
事件中

这就是Xamarin表单中ListView的实现方式。您可以在中找到相同的代码

例如:


您可以将事件添加到
ItemSource
属性的
CollectionChanged
事件中

这就是Xamarin表单中ListView的实现方式。您可以在中找到相同的代码

例如:

可能会有帮助:-它支持项目更新/分组等

示例代码:

<flv:FlowListView x:Name="flowListView" FlowColumnCount="3" SeparatorVisibility="None" HasUnevenRows="false"
    FlowItemTappedCommand="{Binding ItemTappedCommand}" FlowLastTappedItem="{Binding LastTappedItem}"
    FlowItemsSource="{Binding Items}" >

    <flv:FlowListView.FlowColumnTemplate>
        <DataTemplate>
            <Label HorizontalOptions="Fill" VerticalOptions="Fill" 
                XAlign="Center" YAlign="Center" Text="{Binding Title}"/>
        </DataTemplate>
    </flv:FlowListView.FlowColumnTemplate>

</flv:FlowListView> 

可能会有帮助:-它支持项目更新/分组等

示例代码:

<flv:FlowListView x:Name="flowListView" FlowColumnCount="3" SeparatorVisibility="None" HasUnevenRows="false"
    FlowItemTappedCommand="{Binding ItemTappedCommand}" FlowLastTappedItem="{Binding LastTappedItem}"
    FlowItemsSource="{Binding Items}" >

    <flv:FlowListView.FlowColumnTemplate>
        <DataTemplate>
            <Label HorizontalOptions="Fill" VerticalOptions="Fill" 
                XAlign="Center" YAlign="Center" Text="{Binding Title}"/>
        </DataTemplate>
    </flv:FlowListView.FlowColumnTemplate>

</flv:FlowListView> 

您可以尝试

在XAML中使用

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DataGridDemo;assembly=DataGridDemo"
             xmlns:syncfusion="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms" 
             x:Class="DataGridDemo.Sample">

    <ContentPage.BindingContext>
        <local:OrderInfoRepository x:Name="viewModel" />
    </ContentPage.BindingContext>

    <ContentPage.Content>
        <syncfusion:SfDataGrid x:Name="dataGrid"
                               ItemsSource="{Binding OrderInfoCollection}">
        </syncfusion:SfDataGrid>
    </ContentPage.Content>
</ContentPage>

请确保在更新绑定集合后调用属性更改事件


它有许多简洁的功能。

您可以尝试

在XAML中使用

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DataGridDemo;assembly=DataGridDemo"
             xmlns:syncfusion="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms" 
             x:Class="DataGridDemo.Sample">

    <ContentPage.BindingContext>
        <local:OrderInfoRepository x:Name="viewModel" />
    </ContentPage.BindingContext>

    <ContentPage.Content>
        <syncfusion:SfDataGrid x:Name="dataGrid"
                               ItemsSource="{Binding OrderInfoCollection}">
        </syncfusion:SfDataGrid>
    </ContentPage.Content>
</ContentPage>

请确保在更新绑定集合后调用属性更改事件


它有许多简洁的功能。

从Xamarin Forms 3.5中,您可以使用

官方文件中的示例:

<StackLayout BindableLayout.ItemsSource="{Binding User.TopFollowers}"
             Orientation="Horizontal"
             ...>
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <controls:CircleImage Source="{Binding}"
                                  Aspect="AspectFill"
                                  WidthRequest="44"
                                  HeightRequest="44"
                                  ... />
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</StackLayout>

在Xamarin Forms 3.5中,您可以使用

官方文件中的示例:

<StackLayout BindableLayout.ItemsSource="{Binding User.TopFollowers}"
             Orientation="Horizontal"
             ...>
    <BindableLayout.ItemTemplate>
        <DataTemplate>
            <controls:CircleImage Source="{Binding}"
                                  Aspect="AspectFill"
                                  WidthRequest="44"
                                  HeightRequest="44"
                                  ... />
        </DataTemplate>
    </BindableLayout.ItemTemplate>
</StackLayout>


谢谢你的回复-我无法让它工作。我确信这是因为我缺乏理解-你有更全面的例子吗?同时,我也能得到我想要的结果。很抱歉,现在我只能提供示例和伪代码。您提供的链接几乎与此相同,但是通过ObservableCollection实现的。它有一些开销,但我认为你应该是好的。谢谢你的答复-我无法让这个工作。我确信这是因为我缺乏理解-你有更全面的例子吗?同时,我也能得到我想要的结果。很抱歉,现在我只能提供示例和伪代码。您提供的链接几乎与此相同,但是通过ObservableCollection实现的。它有一些开销,但我认为你应该是好的。也许它会有帮助:-它支持项目更新可能会有帮助:-它支持项目更新虽然这个链接可能会回答这个问题,但最好在这里包括答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-添加了代码片段和图像。请注意,这是一个商业产品,因此任何人都可以查看FlowListView或到其他地方寻找解决方案。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,仅链接的答案可能无效。-添加了代码片段和图像,只需注意,这是一个商业产品,因此任何人都可以查看FlowListView或其他地方,为他们的晚间项目寻找解决方案。