2014-02-22 56 views
0

我有幾個按鈕,我想在整個應用程序中使用。如何讓按鈕在整個頁面訪問Windows Phone 7

我的XAML是:

<Button Content="" Grid.Row="1" Height="79" HorizontalAlignment="Left" Margin="9,643,0,0" Name="Home" VerticalAlignment="Top" Width="77" BorderThickness="0" Click="Home_Click" /> 
    <Button Content="" Grid.Row="1" Height="74" HorizontalAlignment="Left" Margin="108,646,0,0" Name="Map1" VerticalAlignment="Top" Width="67" BorderThickness="0" Click="Map1_Click" /> 
    <Button Content="" Grid.Row="1" Height="71" HorizontalAlignment="Left" Margin="198,649,0,0" Name="City1" VerticalAlignment="Top" Width="70" BorderThickness="0" Click="City1_Click" /> 
    <Button Content="" Grid.Row="1" Height="74" HorizontalAlignment="Left" Margin="295,647,0,0" Name="Cuisine1" VerticalAlignment="Top" Width="74" BorderThickness="0" Click="Cuisine1_Click" /> 
    <Button Content="" Grid.Row="1" Height="71" HorizontalAlignment="Left" Margin="398,649,0,0" Name="Share" VerticalAlignment="Top" Width="67" BorderThickness="0" Click="Share_Click" /> 

誰能告訴我如何用我的所有網頁這些按鈕,無需增加他們所有的時間?

回答

1

您可以使用其中的所有按鈕創建UserControl

<UserControl x:Class="WPAppTests.ButtonsUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}"> 

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}"> 
     <!-- Buttons --> 
    </Grid> 
</UserControl> 

當你需要使用這個按鈕,粘貼此代碼在您的網頁:

xmlns:wpAppTests="clr-namespace:WPAppTests" <!-- Your own path to the UserControl --> 

<wpAppTests:ButtonsUserControl /> 

我希望這將有助於!