Я делаю код для входа в бизнес-приложение Silverlight,
и моя проблема в том, что когда мое окно входа закроется, оно перейдет к методу updateStatus()
в MainPage.xaml.cs
. В методе updateStatus()
я хочу, чтобы имя пользователя отображалось, а содержимое кнопки входа изменялось на выход из системы, ниже приведен мой код. Это странно, когда я вхожу, он только открывает приветственное сообщение и не делает код для свойств. Я пытался вставить код в кнопку, и она работает, когда кнопка нажата.
Итак, как мне решить эту проблему?
public void UpdateStatus()
{
if (WebContext.Current.Authentication.User.Identity.IsAuthenticated)
{
lblUser.Visibility = System.Windows.Visibility.Visible;
string nameUSer = WebContext.Current.Authentication.User.Identity.Name;
lblUser.Content = nameUSer;
hbLogin.Content = "Logout";
System.Windows.Browser.HtmlPage.Window.Alert("Welcome" + nameUSer);
}
else
{
lblUser.Visibility = System.Windows.Visibility.Collapsed;
hbLogin.Content = "Login";
}
}
здесь MainPage.xaml
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
xmlns:dataControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:ee="http://schemas.microsoft.com/expression/2010/effects"
x:Class="BusinessApplication1.MainPage"
d:DesignWidth="640" d:DesignHeight="480" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White" Visibility="Visible">
<Grid x:Name="NavigationGrid" Margin="28,82,39,0" Height="34" VerticalAlignment="Top" >
<HyperlinkButton x:Name="Link1"
NavigateUri="/Home" TargetName="ContentFrame" Content="{Binding ApplicationStrings.HomePageTitle, Source={StaticResource ResourceWrapper}}" Margin="8,5,0,0" FontSize="21.333" Foreground="#FF24669D" RenderTransformOrigin="0.5,0.5" Height="31" VerticalAlignment="Top" HorizontalAlignment="Left" Width="68" d:LayoutOverrides="HorizontalAlignment">
<HyperlinkButton.RenderTransform>
<CompositeTransform/>
</HyperlinkButton.RenderTransform>
</HyperlinkButton>
<HyperlinkButton x:Name="Link2"
NavigateUri="/About" TargetName="ContentFrame" Content="{Binding ApplicationStrings.AboutPageTitle, Source={StaticResource ResourceWrapper}}" FontSize="18.667" Foreground="#FF245485" Margin="0,5,405,0" HorizontalAlignment="Right" Width="75" Height="28" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5">
<HyperlinkButton.RenderTransform>
<CompositeTransform/>
</HyperlinkButton.RenderTransform>
</HyperlinkButton>
<HyperlinkButton Content="Login" x:Name="hbLogin" Click="hbLogin_Click" Foreground="#FF69A4D6" FontSize="14.667" HorizontalAlignment="Left" Width="73" RenderTransformOrigin="0.5,0.5" d:LayoutOverrides="HorizontalAlignment, Height" Margin="436,8,0,0">
<HyperlinkButton.RenderTransform>
<CompositeTransform/>
</HyperlinkButton.RenderTransform>
</HyperlinkButton>
<HyperlinkButton Content="More>>" HorizontalAlignment="Left" Margin="168,5,0,5" x:Name="hyperlinkButton1" Width="67" IsTabStop="True" Click="hyperlinkButton1_Click" FontSize="14.667" Foreground="#FF245485" d:LayoutOverrides="HorizontalAlignment" />
<sdk:Label HorizontalAlignment="Right" Margin="0,5,9,0" x:Name="lblUser" Width="63" FontWeight="Bold" Visibility="Collapsed" Foreground="#FFEFAEAE" d:LayoutOverrides="HorizontalAlignment" Height="28" VerticalAlignment="Top" />
</Grid>
<Border x:Name="ContentBorder" d:LayoutOverrides="HorizontalAlignment" Margin="28,120,39,0" >
<navigation:Frame x:Name="ContentFrame"
Source="/Home" NavigationFailed="ContentFrame_NavigationFailed" Margin="8,0" >
<navigation:Frame.Background>
<ImageBrush Stretch="Fill"/>
</navigation:Frame.Background>
<navigation:Frame.UriMapper>
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
</uriMapper:UriMapper>
</navigation:Frame.UriMapper>
</navigation:Frame>
</Border>
<!-- LoginStatus will be added here in code behind. This is required for the designer view to work -->
</Grid>