<ContentControl x:Class="Test.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="200" Height="200" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Fill="Blue"/>
<ContentPresenter Grid.Row="1" Content="{TemplateBinding ContentControl.Content}" />
<Rectangle Fill="Yellow" Grid.Row="2"/>
</Grid>
</ContentControl>
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Test="clr-namespace:Test" Title="MainWindow" Height="350" Width="525">
<Grid>
<Test:MyControl2>
<Button/>
</Test:MyControl2>
</Grid>
</Window>
該按鈕應該出現在藍色和黃色矩形之間。爲什麼我的按鈕不出現在ContentPresenter區域中?
我在做什麼錯?
我不認爲你可以把一個按鈕的用戶控件內部這樣,你爲什麼不把按鈕控件內? – Habib 2012-04-22 15:49:00