• 引用prism的MVVM示例


    VS2013测试通过by一剑

    MainModel.cs

    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

    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

    <UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        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>
    

     

  • 相关阅读:
    我在D2讲演的视频,已经可以下载了~
    走出海量数据及访问量压力困境
    博客作者应该学习的15个国外博客
    如何将jsp动态网页转换成静态页面
    新一代网络模式Web 2.0火爆发展
    数据库设计中的14个关键技巧
    如何进行RSS推广
    运用RUP 4+1视图方法进行软件架构设计
    02java关键词变量类型
    03java运算符函数
  • 原文地址:https://www.cnblogs.com/aswordok/p/3641133.html
Copyright © 2020-2023  润新知