在WPF中查看模型和视图 [英] View Models and View in WPF

查看:86
本文介绍了在WPF中查看模型和视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我有一个使用mvvm模式的wpf应用程序,在我的应用程序中我有两个视图模型,一个控制我的主窗口,另一个控制我的页面。我希望能够将我的登录页面UI元素绑定到我的LoginViewModel?关于该做什么的任何想法谢谢以下是我的两个视图模型的代码



主窗口视图模型

Hi guys I have a wpf application that is using the mvvm pattern, in my application I have two view model, One controls my main window and the other control my page. I want to be able to bind my login page UI element to my LoginViewModel? Any idea on what to do thanks below is my code for my two view model

Main Window view model

#region Displayed page
       private Uri displayedPage;

       public Uri DisplayedPage
       {
           get
           {
               return this.displayedPage;
           }
           set
           {
               this.displayedPage = value;
               base.OnPropertyChanged("DisplayedPage");
           }
       }

       #endregion
       #endregion

       #region Constructor
       public MainWindowViewModel()
       {
           LoginViewModel _login = new LoginViewModel(this);
       }
       #endregion





而我的页面的视图模型



while the view model for my page

#region Constructor
        public LoginViewModel(MainWindowViewModel _mainwin)
        {
            _mainViewModel = _mainwin;
            _mainViewModel.DisplayedPage = new Uri("/View/AuthenticationView/LoginPage.xaml", UriKind.RelativeOrAbsolute);
        }
        #endregion





,这是我的页面的代码



and this is the code for my page

<TextBlock Grid.Row="2" HorizontalAlignment="Left" Name="UsrNmTxtBlk" Text="Username :" VerticalAlignment="Top" Padding="3" Margin="3,0,0,0" Grid.ColumnSpan="2" />
        <TextBox Grid.Row="3" Height="40" Name="UserNmTxtBx" Margin="3" Grid.ColumnSpan="2" VerticalContentAlignment="Center" Text="{Binding Path=OperatorUserID}"/>
        <TextBlock Grid.Row="4" HorizontalAlignment="Left" Name="UsrPassBlk" Text="Password :" VerticalAlignment="Top" Padding="3" Grid.ColumnSpan="2" />
        <PasswordBox Grid.Row="5" Height="40" HorizontalAlignment="Stretch" Name="UserPassTxtbx" Margin="3" Grid.ColumnSpan="2" VerticalContentAlignment="Center" 

                     passhelper:PasswordBxHelper.BindPassword="True"

                     passhelper:PasswordBxHelper.BoundPassword="{Binding Path=OperatorPassword}"/>
        <Button Content="Login" Grid.Column="1" Grid.Row="6" Height="40" 

                HorizontalAlignment="Right" Margin="3" Name="LogInBtn" 

                Width="78" Grid.ColumnSpan="2" />

推荐答案

这绝不是一个简短的解决方案,但我保证如果您通过这两个教程,您将得到答案:



http://www.youtube.com/watch?v=EpGvqVtSYjs [ ^ ]





http://www.youtube.com/watch?v=Dzv8CtUCchY&list=PLjQ72_Gz8xurTQjNh8miqnTFzHlhmhSDw [ ^ ]
By no means is this a short solution, but I guarantee if you go through these two tutorials you will have your answer:

http://www.youtube.com/watch?v=EpGvqVtSYjs[^]


http://www.youtube.com/watch?v=Dzv8CtUCchY&list=PLjQ72_Gz8xurTQjNh8miqnTFzHlhmhSDw[^]


这篇关于在WPF中查看模型和视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆