根據您想要達到的目標,您可以在Button.Content屬性中設置您的UIElement。
該Button.Content屬性可以接受任何UIElement。
例如,你可以做到以下幾點:
MainPage.xaml中
<Page ...>
<StackPanel ...>
<Button x:Name="myButton" Width="200" Height="200"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch" >
<Button.Content>
<local:Page2 />
</Button.Content>
</Button>
</StackPanel>
</Page>
Page2.xaml
<Page...>
<Grid ...>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Rectangle Fill="Red" />
<Rectangle Fill="Yellow" Grid.Column="1"/>
<Rectangle Fill="Blue" Grid.Row="1"/>
<Button Content="Click Me" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center"/>
</Grid>
</Page>
或者從後面的代碼:
MainPage.xaml中.cs
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
myButton.Content = new Page2();
}
}
[VisualBrush可能重複不再適用於Windows 8 Metro Apps?](http://stackoverflow.com/questions/9044066/visualbrush-no-longer-works-for-windows-8-metro-apps) – WiredPrairie