开发者

How do you specify the layout manager to use in a ContentPresenter in a custom control in Silverlight 3/4?

I have a custom control I created that has ContentPresenter defined in generic.xaml. I can successfully embed other controls into the custom control, but it appears to inherit the layout manager of the custom control:

<Style TargetType="custom:Widget">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="custom:Widget">
                <Canvas x:Name="LayoutRoot">

                <!-- Custom Line, Ellipse code using Canvas from above... -->

                    <Grid>
                    <!-- This more local layout manager is overridden...why ? -->

                        <ContentPresenter x:Name="ContentPresenter"
                                          Content="{TemplateBinding Content}" 
                                          ContentTemplate="{TemplateBinding 
                                              ContentTemplate}"/>
                    </Grid>
etc.....

In this case, I use a Canvas for the custom control, whereas I would like to specify something like Grid as the layout manager for the control开发者_开发技巧s added to Content. How do I do this ?

Thanks,

Scott


Scott,

Just make sure that your custom control (custom:Widget) derives from ContentControl and not Control. Only ContentControl pay attention to ContentPresenters in the visual tree.

Jim McCurdy
YinYangMoney

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜