3

I explain my issue as I'm quite new to UI design :

I have a main View which displays a TreeView on its left part. When an element is selected I'd like to show a description of the Item on the right on the same window. The design of this description depends on the nature of the Item. So I created a View per Item Type corresponding to the different possible design.

Now When I click on the TreeView I have no idea how to show the corresponding view on the right of the same window. (I'm not asking about catching the event, just displaying a view within another view, like if I dynamically plotted a control).

Is it possible ? If not what kind of approach would you suggest ?

Many Thanks.

qwark
  • 493
  • 1
  • 4
  • 15
  • 2
    https://www.google.de/search?q=wpf+usercontrol – Joel Mar 01 '14 at 00:10
  • Ok Thank you for this. It will do the trick for now. But what if I really need it to be a view not a control so it has its own dispatcher thread. Is there a way ? – qwark Mar 01 '14 at 00:20

1 Answers1

2

This seems like a great candidate for a Data Template.

Basically, create a content presenter and bind its content property to the TreeView's SelectedItem property. Now, create data templates for each of your types (using the DataType property) in the ContentTemplate property.

Now, the correct data template will be chosen with the correct data whenever you select something in your tree view.

As far as a separate dispatcher goes, I'm not sure, but I'm also not sure what scenario would require one.

More information can be found in this SO question.

Sample:

    <ContentPresenter Content="{Binding Path=SelectedItem, ElementName=TreeView}">
        <ContentPresenter.ContentTemplate>
            <DataTemplate DataType="{x:Type Type1}">
                <!-- Bunch of stuff-->
            </DataTemplate>
            <DataTemplate DataType="{x:Type Type2}">
                <!-- Bunch of stuff-->
            </DataTemplate>
        </ContentPresenter.ContentTemplate>
    </ContentPresenter>
Community
  • 1
  • 1
BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117