Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Canvas Binding

I'm rather new to WPF, so maybe this is a simple question. I have a class that derives from Canvas, let's call it MyCanvas. And I have a class, MyClass, that has a property of type MyCanvas. In XAML, I built a TabControl, so each TabItem binds to a MyClass object. Now, in the Content of every tab I want to display MyObject.MyCanvas.

How should I do that?

<TabControl.ContentTemplate>
    <DataTemplate>
        <Grid>
            <myCanvas:MyCanvas  Focusable="true" Margin="10" >
                <Binding Path="Canvas"></Binding>
            </myCanvas:MyCanvas>
        </Grid>
    </DataTemplate>
</TabControl.ContentTemplate>
like image 887
morsanu Avatar asked May 21 '26 05:05

morsanu


1 Answers

You should use ContentPresenter

<TabControl.ContentTemplate> 
    <DataTemplate> 
        <Grid> 
            <ContentPresenter Content="{Binding MyCanvas}" Focusable="true" Margin="10" />
        </Grid> 
    </DataTemplate> 
</TabControl.ContentTemplate>
like image 191
bniwredyc Avatar answered May 22 '26 17:05

bniwredyc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!