Sonic Soul
Sonic Soul

Reputation: 24919

WPF: applying a converter to ItemsSource

is it possible to apply a converter to a data source of a control in xaml?

or perhaps there is another way to do this.

Basically i have a custom control that accepts a specific type of object. that object is tightly bound to that control. I don't want to convert to this type all over my view model. So i would like to be able to bind to regular properties such as List and have it automatically translated to my object by a converter.

I've attempted something like this.

ItemsSource="{Binding CurrentTables, Converter={x:Static cconverters:SpyFilterDataObjectConverter}}" 

Upvotes: 3

Views: 5617

Answers (2)

madcyree
madcyree

Reputation: 1457

Well, it doesn't seem good as for me to use such kind of converters. Basically, converter performs conversion operation only once, so you will not receive any updates. I've used different approach - just create some sort of wrapper that contains an initial collection (it should implement INotifyCollectionChanged) and some wrap strategies that converts your initial object to wrapped one.

Upvotes: 1

brunnerh
brunnerh

Reputation: 184647

x:Static has the syntax namespace:Type.StaticMember, you should instantiate the converter and expose it as a static property.

Alternatively you can create an instance in the Application.Resources in your App.xaml, then you can reference it as a static resource throughout the application using its key.

Upvotes: 1

Related Questions