我定义了一个包含如下代码的按钮的资源。
<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>
我喜欢通过XAML编码将控件放入Window1。
请帮帮我。
答案 0 :(得分:3)
<StaticResource ResourceKey="btnMy"/>
如果你在不止一个地方使用它,你会得到一些不错的例外......
编辑:有些人可能会感兴趣的是,可以通过在相关资源上将x:Shared
设置为false来避免这些异常,从而导致新创建控件它被引用。