I am looking into the logistics of adding several WPF features to a 1,000,000+ line code-base. I am looking into using databinding and DataTemplates in XAML to easily display various objects. I am able to bind an observable collection: points
to a ListBox and if I don t use a template, I can just provided a meaningful toString for the list items and that gets me somewhere. The problem comes in when I want to use a template to display various properties of the list items. It is my understanding that they all have to be DependencyProperties. parent
is just a property. It looks like adding dependency properties is fairly complicated. All the classes you want to display have to inherit from DependencyObject
and you have to set a bunch of stuff for each property you want to use. This does not seem feasible for a large codebase, to have to do all this for each property.
I m wondering how databinding is used in practice, do you really add crap-tons of dependency properties to all of your classes or is there a better way?
谢谢!
<ListBox Name="listBox1"
ItemsSource="{Binding Source={StaticResource points}}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="Point!"/>
<TextBlock Text="{Binding parent}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>