如何在Windows Phone 7中的整个页面中访问按钮

时间:2014-02-22 07:17:02

标签: c# 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 个答案:

答案 0 :(得分: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 />

我希望这会有所帮助!