Sys
Sys

Reputation: 413

WPF Custom binding Collection to non dependency property

I've created my own custom binding class and added a property to it:

public BindingGroupCollection BindingGroups
{
    get { return validationResultGroup; }
    set { validationResultGroup = value; }
}

public class BindingGroupCollection : ObservableCollection<BindingGroup> { } 

In my xaml class i declared the objects and collection:

<local:BindingGroup x:Key="BG1"/>
<local:BindingGroup x:Key="BG2"/>

<local:BindingGroupCollection x:Key="BindingGroups1">
   <StaticResourceExtension ResourceKey="BG1"/>
   <StaticResourceExtension ResourceKey="BG2"/>
</local:BindingGroupCollection>

And i want to use this in my binding eg.:

<TextBox Text="{local:CustomBinding BindingGroups={Binding Source={StaticResource BindingGroups1}}}"/>

But i get an error that the target is not a dependeny object. Any help?

Upvotes: 0

Views: 382

Answers (1)

Thomas Levesque
Thomas Levesque

Reputation: 292465

You can't do that, because a Binding isn't a DependencyObject, so it can't have have dependency properties.

However, in your case you don't need a binding, you can use the StaticResource directly:

<TextBox Text="{local:CustomBinding BindingGroups={StaticResource BindingGroups1}}"/>

Upvotes: 2

Related Questions