2011-07-21 56 views
0

我想要做這樣的事情:如何將控件定義爲資源並將其放置到表單上?

<Window x:Class="WpfApplication10.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="350" Width="525"> 
    <Window.Resources> 
     <Button x:Key="butt" Content="Yeah!" /> 
    </Window.Resources> 
    <Grid> 
     <!-- Place button here --> 
    </Grid> 
</Window> 

怎麼辦呢?我想在單個文件中創建小型用戶控件庫。

回答

2
<Grid> 
    <StaticResource ResourceKey="butt"/> 
</Grid> 

應該工作...

+0

酷!沒有想到它可以在綁定之外使用(標記表達式)。 – Poma

+0

@Poma:您可以使用元素語法使用所有標記擴展,這在某些情況下非常有用,例如這個。如果您只在一個地方使用轉換器,則可以使用此語法在綁定中創建它。 –

+0

不要忘記設置Grid.Row和列屬性:) –

相關問題