Using data binding on value which is a FrameworkElement

Posted by JaredPar on Stack Overflow See other posts from Stack Overflow or by JaredPar
Published on 2010-04-02T07:43:38Z Indexed on 2010/04/02 13:43 UTC
Read the original article Hit count: 277

Filed under:
|
|

One of my data sources produces a collection of values which are typed to the following interface

public interface IData
{
    string Name { get; }
    FrameworkElement VisualElement { get; }
}

I'd like to use data binding in WPF to display a collection of IData instances in a TabControl where the Name value becomes the header of the tab and the VisualElement value is displayed as the content of the corresponding tab.

Binding the header is straight forward. I'm stuck though on how to define a template which allows me to display the VisualElement value. I've tried a number of solutions with little success. My best attempt is as follows.

    <TabControl ItemsSource="{Binding}">
        <TabControl.ItemTemplate>
            <DataTemplate>
                <Label Content="{Binding Name}"/>
            </DataTemplate>
        </TabControl.ItemTemplate>
        <TabControl.ContentTemplate>
            <DataTemplate>
                How do I display VisualElement here?
            </DataTemplate>
        </TabControl.ContentTemplate>
    </TabControl> 

I'm still very new to WPF so I could be missing the obvious here.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding