私はListView
からアイテムを削除しています。私もグループヘッダーのカウンターを使用するので、私はそれを更新する必要があります。しかし、私はこれをどのようにすることができますか?これは私のコードです:ListViewからグループヘッダを更新するには?
ListView
:
<ListView x:Name="MyListList"
HasUnevenRows="True"
CachingStrategy="RecycleElement"
IsGroupingEnabled="True"
GroupDisplayBinding="{Binding Key}"
IsPullToRefreshEnabled="True"
RefreshCommand="{Binding LoadDataCommand}"
IsRefreshing="{Binding IsRefreshing, Mode=OneWay}">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<customViews:MyGroupingHeaderCell/>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<customViews:MyHeaderCell />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
カスタムグループヘッダー:
<?xml version="1.0" encoding="utf-8" ?>
<ViewCell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Views.MyGroupingHeaderCell"
xmlns:customViews="clr-namespace:Views;"
xmlns:renderer="clr-namespace:Common.CustomRenderers;">
<renderer:ListViewGroupHeader x:Name="keyName" Style="{StaticResource labelHeader}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
</ViewCell>
public partial class MyGroupingHeaderCell : ViewCell
{
public MyGroupingHeaderCell()
{
InitializeComponent();
}
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
var item = BindingContext as ObservableGroupCollection<string, CustomObject>;
if (item != null)
{
this.keyName.Text = item.Key + " (" + item.Count + ")";
}
else
{
this.keyName.Text = string.Empty;
}
}
}
私はこのLINQ式
List<ObservableGroupCollection<string, CustomObject>> resultList = rawList.OrderByWithDirection(order, descending)
.GroupBy(group)
.Select(p => new ObservableGroupCollection<string, CustomObject>(p))
.OrderByWithDirection(i => i.Key, false) // sort the group
.ToList();
で
項目ため
Key
を作成します私が今やっていることは、私は完全に元のデータから項目を削除し、再設定することで、
ListView
をリロードということです
:group
は
Func<CustomObject, string> group = p => p.SomeObject.Identification;
考えられるソリューションです
ItemSource
。これは本当に完璧な解決策ではありませんが、機能します。しかし、ObservableCollection
の利点はなくなりました。