我是 Windows Phone 开发的新手。
我需要带有注销按钮的自定义标题,然后在每个页面上使用它。我怎样才能实现这一点?
我是 Windows Phone 开发的新手。
我需要带有注销按钮的自定义标题,然后在每个页面上使用它。我怎样才能实现这一点?
首先,Logout
在应用程序的每个页面的标题中都有一个按钮并不是一个好主意。我建议您ApplicationBar
用于此目的并在那里添加一个 logout MenuItem
。主要思想是注销操作不经常使用,所以隐藏了。并将您的注销逻辑添加到基PhoneApplicationPage
类或基ViewModel
类。如果使用 anApplicationBar
不适合您,您可以使用UserControl
并将其添加到每个应用程序页面。标题示例UserControl
<UserControl x:Class="PhoneApp3.LogoutUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<StackPanel>
<Image Source="/Images/Header.jpg"/>
<Button Click="Logout" Content="Logout"/>
</StackPanel>
</Grid>
</UserControl>
你的主页看起来像
<phone:PhoneApplicationPage
x:Class="PhoneApp3.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:userControls="clr-namespace:PhoneApp3"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<userControls:LogoutUserControl Grid.Row="0" x:Name="HeaderControl"/>
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
</Grid>
</Grid>
</phone:PhoneApplicationPage>