Я использую DynamicData от Roland Pheasant.
DynamicData
Я хотел бы преобразовать мои обычные коллекции C # в Rx.
С
ObservableCollection<Grouping<string, DisplayItem>>
в формате DynamicData
ReadOnlyObservableCollection<IGroup<DisplayItem, string>>
или
ReadOnlyObservableCollection<IGroup<DisplayItem, string, string>>
для кэшированного источника.
В настоящее время мой xaml будет выглядеть следующим образом для привязки к обычному ObservableCollection<Grouping<string, DisplayItem>>
<CollectionViewSource
x:Name="GroupedDataCollection"
Source="{x:Bind ViewModel.bindingData_grouped, Mode=OneWay}"
IsSourceGrouped="True" />
<ListView
Margin="16,0"
ItemsSource="{x:Bind GroupedDataCollection.View , Mode=OneWay}"
SelectionMode="None">
<ListView.GroupStyle>
<GroupStyle HidesIfEmpty="False">
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock FontSize="14"
FontWeight="SemiBold"
Text="{Binding Key }" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemTemplate >
<DataTemplate x:DataType="viewmodels:DisplayItem">
<StackPanel>
<TextBlock FontSize="14"
FontWeight="SemiBold"
Text="{x:Bind Description }" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Модель:
public class DisplayItem {
public string ID { get; set; } = Guid.NewGuid().ToString();
public string Type { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
public double? Price { get; set; } = 0; }
Существующие результаты c # Observable Collection:
![Existing results](https://i.stack.imgur.com/gj72s.png)
Код динамических данных:
public ReadOnlyObservableCollection<IGroup<DisplayItem, string>> bindingData_grouped;
var myBindingOperation_grouped = Data.ToObservableChangeSet()
.GroupOn(x => x.Type)
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out bindingData_grouped)
.Subscribe();
Используя приведенный выше код, если я связываюсь с ReadOnlyObservableCollection<IGroup<DisplayItem, string>>
или ReadOnlyObservableCollection<IGroup<DisplayItem, string, string>>
, мой просмотр списка ничего не показывает.
Как связать из списка xaml с помощью «CollectionViewSource» в
ReadOnlyObservableCollection<IGroup<DisplayItem, string>>
или
ReadOnlyObservableCollection<IGroup<DisplayItem, string, string>>
спасибо заранее.