tags:

views:

53

answers:

1

Hi,

I'm starting to use Binding in my WPF project and I'm actually confused about few things on the presentation side (XAML).

So I want to populate a tree view with a List of Categories. I know how to write the right HierarchicalDataTemplate for my List of Category instances.

<HierarchicalDataTemplate ItemsSource="{Binding Path=ChildrenCategories}" DataType="{x:Type src:Category}">
      <TextBlock Text="{Binding Path=Name}"></TextBlock>
</HierarchicalDataTemplate>

But what now I don't know is from where to get the list. I have here 2 solutions :

  1. I got a Library Singleton class which return me the right arborescence, then I need to use an ObjectDataProvider in my xaml which would call the Library.Instance.Categories method. (Which means that the controller has to be completely separated from the UI).

  2. I got a Property ListCategories in my page interactionLogic (OpenUnit.xaml.cs), and bind the tree with it.

I'm not sure about the purpose of the xaml.cs files, what are they made for? Is it normally used to store the properties (and act as a controller) or simply to have a back-end for the UI (for example get values from the UI?)?

In case the xaml.cs file is used as a controller, how do I bind my data to it, I've tried many solutions without success,my only success was with the use of static binding.

I would appreciate any comment or recommandation about UI and Logic Binding in WPF, hopefully I will get less confused.

Thanks in advance,

Boris

A: 

After reading this great article, I got a little bit less confused :

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

The article is about the Model View ViewController pattern, and how WPF integrates it. So it seems that xaml.cs files should be used as the ViewController here, and should hold the properties. It actually make sense since it's not a good practice to mix the View and the Data, we want the designers should have a completely independant work to do.

Also for the solution 2) it is possible if you set the data context to the current file.

Boris Gougeon