开发者

How do I add an element to the visual tree in Silverlight

Here is my specific problem:

Xaml:

<local:ShrinkableContentControl x:Name="m_ShrinkableContentControl">
    <Border Background="SkyBlue">
        <Button Click="Button_Click_1" Content="Hello"/>
    </Border>
</local:ShrinkableContentControl>

Code for ShrinkableContentControl:

[ContentProperty("Shrinkable")]
public class ShrinkableC开发者_开发百科ontentControl : FrameworkElement
{
    protected override Size MeasureOverride(Size availableSize)
    {
        return base.MeasureOverride(availableSize);
    }

    protected override Size ArrangeOverride(Size finalSize)
    {
        this.Shrinkable.Arrange(new Rect(0, 0, 100, 100));
        return base.ArrangeOverride(finalSize);
    }

    public FrameworkElement Shrinkable { get; set; }
}

The issue here is, Shrinkable is Content, and is not added in to the visualtree, so nothing gets displayed.

Can anyone tell me if there is a way to add the Shrinkable as a child of ShrinkableContentControl in the visualtree?

Thanks, Henry


If you want a single child, it sounds like you should inherit from ContentControl:

Represents a control with a single piece of content of any type.

Just set the Content property

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜