开发者

Programmatically set the PivotViewer's filters

I have a Silverlight PivotViewer up and running, with about 4000 items.

I pass querystring 开发者_Go百科parameters to the page that hosts the PivotViewer, to filter the items upon opening.

How do you add filters to the PivotViewer programmatically?

I've tried :

pvtTest.AppliedFilters.Add(new KeyValuePair<string, IList<string>>("Color", new List<string> { "EQ.Green", "EQ.Red" }));

but it still displays all the items. I've also tried checking what the value of the AppliedFilters property is after I set some filters using the UI, but it still only contains the filter that I added above.


For PivotViewer-2

string sFilter = pvViewer.Filter; //get existing filter

pvViewer.ItemsSource = new-data-source; //assign new data source

pvViewer.Filter = sFilter; //reassign filter


I think the answer by grimstoner might not be clear enough.

You can indeed use the ViewerState property to set filters, but you cannot set it directly as it only has a public getter. The workaround is to use the LoadCollection() method passing the URI of the already loaded collection and the modified viewer state. You might expect that the Pivot Viewer will reload the collection, but this is not the case. It seems smart enough to detect the identical URI and only applies the new viewer state.

Example:

string viewerState = pivotViewer.ViewerState;

// Modify the viewer state according to the rules defined at:
// http://www.silverlight.net/content/pivotviewer/developer-info/api/html/P_System_Windows_Pivot_PivotViewer_ViewerState.htm

pivotViewer.LoadCollection(pivotViewer.CollectionUri.ToString(), viewerState);

I hope this helps others with the same question.


You can specify filters by using the ViewerState property.

It has a very specific syntax, which can be found here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜