【发布时间】:2023-03-23 22:04:01
【问题描述】:
我有一个名为 btnLogin 的按钮,我希望在变量更改时更改此按钮的内容。基本上我有一个登录屏幕,一旦用户登录成功,我正在设置一个变量,并根据这个变量,我希望内容改变。
所以现在我有一个登录屏幕并且在登录时,我正在设置这个变量:-
ApplicationState.SetValue("UserLoggedIn", "True");
然后在主屏幕中,当加载窗口时,我有这段代码:-
private void CheckLoginButton()
{
//check if user is checked in or out
if (String.IsNullOrEmpty(ApplicationState.GetValue<string>("UserLoggedIn")))
{
//User not logged in
ImageSource largeImageSource =
new BitmapImage(new Uri(@"/myAppWPF;component/Images/administrator-icon32.png", UriKind.Relative));
ImageSource smallImageSource =
new BitmapImage(new Uri(@"/myAppWPF;component/Images/administrator-icon16.png", UriKind.Relative));
btnLogin.LargeImageSource = largeImageSource;
btnLogin.SmallImageSource = smallImageSource;
btnLogin.Label = "Login";
btnLogin.ToolTipTitle = "Please Log In";
}
else
{
//User logged in
ImageSource largeImageSource =
new BitmapImage(new Uri(@"/myAppWPF;component/Images/logout32.png", UriKind.Relative));
ImageSource smallImageSource =
new BitmapImage(new Uri(@"/myAppWPF;component/Images/logout16.png", UriKind.Relative));
btnLogin.LargeImageSource = largeImageSource;
btnLogin.SmallImageSource = smallImageSource;
btnLogin.Label = "Log Out";
btnLogin.ToolTipTitle = "Log Out";
}
}
在 XAML 中我有以下内容:-
<r:RibbonGroup Name="AdminGroup" Header="Admin" >
<r:RibbonButton Name="btnLogin" Click="btnLogin_Click" ></r:RibbonButton>
</r:RibbonGroup>
然而,每次 btnLogin 总是设置为 Login 而从不注销,即使变量设置正确。
我需要重新注册这个按钮吗?还是我做错了什么?
感谢您的帮助和时间
【问题讨论】:
-
窗口是在登录前加载还是在登录后加载?
标签: wpf button user-controls wpf-controls