0
votes

I have been working on a CustomControl which contains an ItemsControl. I have added a dependency property so i can set the ItemsSource property of the ItemsControl in the XAML where the control is used. I have declared my array of custom objects directly in the XAML. This works quite nicely however i have hit a problem with binding any of the public properties on the custom objects in the XAML. The custom objects are not dependency objects...

I would appreciate some pointers.

If this is too convoluted to achieve in XAML i will just bind the ItemsSource to a property on my view model...

XAML:

<local:OptionsControl Title="Options" Message="Select an option:">
    <local:OptionsControl.Options>
        <x:Array Type="{x:Type local:OptionInfo}">
           <local:OptionInfo Name="OptionOne" SelectCommand="{Binding ?"}/>
           <local:OptionInfo Name="OptionTwo" SelectCommand="{Binding ?"}/>
           <local:OptionInfo Name="OptionThree" SelectCommand="{Binding ?"}/>
        </x:Array>
    </local:OptionsControl.Options>
</local:OptionsControl>           
1
This doesn't seem to make any sense. Why would you give your custom control an ItemsSource dependency property and then try to declare the items in the XAML itself? And then bind their own properties to other data? Please correct me if I'm wrong but it's seems like you think you need to bind to DependencyObjects or something?Mark Feldman

1 Answers

0
votes

You don't explain fully what you are doing.

You can define an x:array with a type and bind the itemssource to that. You can bind to pubic properties of that type, no problem.

You can even define a class inherits observablecollection, define the items of that in xaml and bind an itemssource to that.

https://social.technet.microsoft.com/wiki/contents/articles/26200.wpf-dynamicresource-observablecollection.aspx