WinRT XAML Toolkit BindableSelections未更新UI

WinRT XAML Toolkit BindableSelections未更新UI,xaml,windows-runtime,winrt-xaml,mvvm-light,winrt-xaml-toolkit,Xaml,Windows Runtime,Winrt Xaml,Mvvm Light,Winrt Xaml Toolkit,下面是在MyGridView中处理选定项的xaml和c#代码 我还使用MVVM Light,一切正常,包括我能够看到SelectedItems中的内容 但是,当我尝试清除SelectedItems时,我的UI似乎没有更新/反映对SelectedItems所做的更改 我正在使用WinRT XAML Toolkit(),它在GridView上具有BindableSelection扩展 XAML <controls:CustomGridView x:Name="VideoItemGrid

下面是在MyGridView中处理选定项的xaml和c#代码

我还使用MVVM Light,一切正常,包括我能够看到SelectedItems中的内容

但是,当我尝试清除SelectedItems时,我的UI似乎没有更新/反映对SelectedItems所做的更改

我正在使用WinRT XAML Toolkit(),它在GridView上具有BindableSelection扩展

XAML

<controls:CustomGridView
    x:Name="VideoItemGridView"
    Grid.Row="2"
    Margin="0,-3,0,0"
    Padding="116,0,40,46"
    HorizontalContentAlignment="Stretch"
    VerticalContentAlignment="Stretch"
    IsItemClickEnabled="True"
    SelectionMode="Extended"
    Extensions:GridViewExtensions.BindableSelection="{Binding SelectedVideoItems, Mode=TwoWay}"
    ItemsSource="{Binding Source={StaticResource ViewSource}}"
    ItemTemplate="{StaticResource VideoItemTemplate}">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <VariableSizedWrapGrid ItemWidth="250" ItemHeight="160" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</controls:CustomGridView>

MyViewModel.cs

#region Selected Items

/// <summary>
/// Gets or sets the selected video items.
/// </summary>
public ObservableCollection<object> SelectedVideoItems
{
    get { return this._selectedVideoItems; }
    set
    {
        this._selectedVideoItems = value;
        this.Set("SelectedVideoItems", ref this._selectedVideoItems, value);
    }
}
private ObservableCollection<object> _selectedVideoItems = new ObservableCollection<object>();

#endregion

#region App Bar Click Commands

/// <summary>
/// Gets the ClearSelection click command.
/// </summary>
public ICommand ClearSelectionClickCommand
{
    get
    {
        return new RelayCommand(() => this.ClearSelectionOperation());
    }
}

/// <summary>
/// Selects all command operation.
/// </summary>
private void ClearSelectionOperation()
{
    this.SelectedVideoItems = new ObservableCollection<object>();
}

#endregion
#区域所选项目
/// 
///获取或设置选定的视频项目。
/// 
公共可观察收集选定的视频项目
{
获取{返回此。\u selectedVideoItems;}
设置
{
这是。\ u selectedVideoItems=值;
此.Set(“SelectedVideoItems”,ref this.\u SelectedVideoItems,value);
}
}
私有ObservableCollection_selectedVideoItems=新ObservableCollection();
#端区
#区域应用程序栏单击命令
/// 
///获取“单击”命令。
/// 
公共ICommand清除选择单击命令
{
得到
{
返回新的RelayCommand(()=>this.ClearSelectionOperation());
}
}
/// 
///选择所有命令操作。
/// 
私有无效清除选择操作()
{
this.SelectedVideoItems=新的ObservableCollection();
}
#端区

ClearSelectionOperation
中,通过调用

this.SelectedVideoItems.Clear();
而不是

this.SelectedVideoItems = new ObservableCollection<object>();
this.SelectedVideoItems=新的ObservableCollection();

如果这无助于检查是否修复了问题。

结果表明,由于我使用的是数据模板,因此实际上是我的数据模型需要设置一个标志来指示它已被选中

这是拼图中缺失的部分。更新绑定到网格视图项的数据模型(还包括对行/列扩展的支持)后,UI将按预期更新

希望这能帮助别人

public class CustomGridView : GridView
{
    protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
    {
        try
        {
            base.PrepareContainerForItemOverride(element, item);

            dynamic _Item = item;
            element.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, _Item.ColumnSpan);
            element.SetValue(VariableSizedWrapGrid.RowSpanProperty, _Item.RowSpan);
            element.SetValue(GridViewItem.IsSelectedProperty, _Item.IsSelected);
        }
        catch
        {
            element.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 1);
            element.SetValue(VariableSizedWrapGrid.RowSpanProperty, 1);
            element.SetValue(GridViewItem.IsSelectedProperty, false);
        }
        finally
        {
            base.PrepareContainerForItemOverride(element, item);
        }
    }

您使用的是源代码中的工具包的当前版本还是NuGet包?最近(3月7日)有一些更新尚未进入新的NuGet包。