【发布时间】:2012-03-21 18:25:09
【问题描述】:
我有一个超链接按钮,如果登录成功,我在按钮中设置点击内容后面的代码到新视图。
private void OkButtonClick(object sender, RoutedEventArgs e)
{
LoginOperation loginOp = FLS.Utilities.RIAWebContext.Current.Authentication.Login(
new LoginParameters(usernameTextBox.Text, passwordTextBox.Text));
loginOp.Completed += (s2, e2) =>
{
if (loginOp.HasError)
{
errorTextBlock.Text = loginOp.Error.Message;
loginOp.MarkErrorAsHandled();
return;
}
else if (!loginOp.LoginSuccess)
{
errorTextBlock.Text = "Login failed.";
return;
}
else
{
errorTextBlock.Text = string.Empty;
Content = new WelcomeView();
}
};
}
我现在将 MVVM 的代码移到了视图模型中,并在超链接按钮上使用了 delegateCommand。
<UserControl ... >
<Grid ... >
...
<HyperlinkButton Content="Login" Height="23" HorizontalAlignment="Left" Margin="313,265,0,0" Name="loginButton" Command="{Binding Path=LoginCommand}" VerticalAlignment="Top" Width="75"/>
...
</Grid>
</UserControl>
但我不知道,我如何制作 Content = new WelcomeView();来自视图模型中的代码?
【问题讨论】:
标签: silverlight xaml mvvm ria