开发者

Placing an object defined as a resource in the visual tree

I defined a resource which contains a button like following code.

<Window x:Class="WpfApplication1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="313" Width="481">

    <Window.Resources>
        <Button x:Key="btnMy">my button</Button>
    </Window.Resources>

    <!--And now, how can I place 'btnMy' into here?-->
</Window>

And I like to place a control into Window1 开发者_如何学运维by XAML coding.

please help me.


<StaticResource ResourceKey="btnMy"/>

If you use this in more than one place you'll get some nice exceptions...

Edit: It might be of interest to some that these exceptions can be avoided by setting x:Shared to false on the resource in question, that will cause the new creation of a control whereever it is referenced.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜