Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 8 在WinRT中强制重新应用ItemTemplateSelector_Windows 8_Winrt Xaml - Fatal编程技术网

Windows 8 在WinRT中强制重新应用ItemTemplateSelector

Windows 8 在WinRT中强制重新应用ItemTemplateSelector,windows-8,winrt-xaml,Windows 8,Winrt Xaml,我有一个GridView作为SemanticZoom控件中的缩小视图。此GridView使用自定义DataTemplateSelector作为ItemTemplateSelector。它为我的应用程序显示的每个内容组显示一个项目 根据组是否为空,模板会有所不同。这在加载时可以正常工作,但在组变为空或不再为空时不会更新 我发现ItemTemplateSelector仅在第一次显示页面时运行。如何强制再次运行DataTemplateSelector 本主题中的WPF问题都建议使用触发器,但这些触发器

我有一个GridView作为SemanticZoom控件中的缩小视图。此GridView使用自定义DataTemplateSelector作为ItemTemplateSelector。它为我的应用程序显示的每个内容组显示一个项目

根据组是否为空,模板会有所不同。这在加载时可以正常工作,但在组变为空或不再为空时不会更新

我发现ItemTemplateSelector仅在第一次显示页面时运行。如何强制再次运行DataTemplateSelector


本主题中的WPF问题都建议使用触发器,但这些触发器在WinRT XAML中不可用。

我找到了一个类似WPF问题的答案,该问题在WinRT中也适用:

基本上是将ItemTemplateSelector设置为null,然后再次设置。像这样:

var templateSelector = MyGroupView.ItemTemplateSelector;
MyGroupView.ItemTemplateSelector = null;
MyGroupView.ItemTemplateSelector = templateSelector;

这是可行的,但如果有更好的方法,我很高兴被告知。

我发现只需从收藏中删除需要更新的项目并将其添加回来就更容易了。这将强制GridView或ListView应用模板。这在MVVM世界中很容易做到

var itemToReload; //The object who's template needs updating
var reloadIndex  = this.SomeCollection.IndexOf(itemToReload);

this.SomeCollection.Remove(itemToReload);
this.SomeCollection.Insert(reloadIndex, itemToReload);
需要注意的一点是,如果项目是“选定”项目,则需要重新应用该选择