首页 > 其他 > 详细

引用prism的MVVM示例

时间:2014-04-02 19:02:16      阅读:468      评论:0      收藏:0      [点我收藏+]

VS2013测试通过by一剑

bubuko.com,布布扣

MainModel.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
using System.ComponentModel;
 
namespace referencePrismMVVM.Model
{
    public class MainModel
    {
        public int Number1 { get; set; }
 
        public int Number2 { get; set; }
 
        public int Result { get; set; }
    }
}

 MainViewModel.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using referencePrismMVVM.Model ;
using Microsoft.Practices.Prism.Commands;
using System.ComponentModel;
 
namespace referencePrismMVVM.VideModel
{
    public class MainViewModel:INotifyPropertyChanged
    {
        public ICommand AddCommand { get; private set; }
        public MainViewModel()
        {
            this.AddCommand = new DelegateCommand<object>(this.OnSubmit);
        }
 
        private void OnSubmit(object obj)
        {
            Result = Number1 + Number2;
        }
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        public int Number1 { get; set; }
 
        public int Number2 { get; set; }
 
        private int result;
 
        public int Result
        {
            get
            {
                return this.result;
            }
            set
            {
                if (value != this.result)
                {
                    this.result = value;
                    if (this.PropertyChanged != null)
                    {
                        this.PropertyChanged(this, new PropertyChangedEventArgs("Result"));
                    }
                }
            }
        }
    }
}

 

 MainPage.xaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<UserControl
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" x:Class="referencePrismMVVM.MainPage"
    mc:Ignorable="d"
    xmlns:ds="clr-namespace:referencePrismMVVM.VideModel"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <UserControl.DataContext>
        <ds:MainViewModel/>
    </UserControl.DataContext>
 
    <Grid x:Name="LayoutRoot" Background="White">
        <TextBox Text="{Binding Number1, Mode=TwoWay}" HorizontalAlignment="Left" Height="23" Margin="38,142,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="72"/>
        <TextBox Text="{Binding Number2, Mode=TwoWay}" HorizontalAlignment="Left" Height="23" Margin="154,142,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="72"/>
        <Button x:Name="AddButton" Command="{Binding AddCommand}" Content="=" HorizontalAlignment="Left" Margin="243,142,0,0" VerticalAlignment="Top" Width="37"/>
        <sdk:Label HorizontalAlignment="Left" Height="19" Margin="128,145,0,0" VerticalAlignment="Top" Width="15" Content="+"/>
        <sdk:Label Content="{Binding Result,Mode=TwoWay}" HorizontalAlignment="Left" Height="16" Margin="295,145,0,0" VerticalAlignment="Top" Width="71"/>
    </Grid>
</UserControl>

 bubuko.com,布布扣

引用prism的MVVM示例,布布扣,bubuko.com

引用prism的MVVM示例

原文:http://www.cnblogs.com/aswordok/p/3641133.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!