• 大小: 3.52MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-28
  • 语言: C#
  • 标签: vue  mvvm  wpf  双向绑定  

资源简介

模仿vue 实现的 在winform 上实现的数据模型双向绑定。升级版使用 castle 进行动态代理,较与旧版节省大量代码的书写,同时将核心抽出来,还能用到其它需要监听属性变化的地方

资源截图

代码片段和文件信息

using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TViewCore;

namespace TView
{
    public class ViewBind
    {
        /// 
        /// 默认绑定事件
        /// 

        private string DefaultEvents = “Collectionchange|SelectedValueChanged|ValueChanged|TextChanged“;
        /// 
        /// 默认绑定的属性,从左往右,能找到则赋值
        /// 

        private string DefaultProperty = “DataSource|Value|Text“;


        /// 
        /// 绑定视图
        /// 

        /// 父控件
        /// 模型(对象)
        public ViewBind(Control ParentControl object model)
        {
            var pg = new ProxyGenerator();
            var pi = new PropertyInterceptor(model);
            model = pg.CreateClassProxy(model.GetType() new IInterceptor[] { pi });
            this.BindingParentControl(ParentControl model);
        }
        /// 
        /// 绑定控件
        /// 

        /// 父控件
        /// 实体
        private void BindingParentControl(Control ParentControl object model)
        {
            this.BindControl(ParentControl model ParentControl.Controls);
        }
        /// 
        /// 绑定控件
        /// 

        /// 父控件
        /// 实体
        /// 子控件列表
        private void BindControl(Control ParentControl object model Control.ControlCollection Controls)
        {
            foreach (Control control in Controls)
            {
                var tag = control.Tag;
                
                if (tag == null) continue;
                foreach (var tagInfo in tag.ToString().Split(‘|‘))
                {
                    var tagInfoArr = tagInfo.Split(‘-‘);
                    //属性绑定
                    if (tagInfoArr[0].Equals(“dt“)|| tagInfoArr[0].Equals(“data“))
                    {
                        var bindProperty = string.Empty;
                        if (tagInfoArr.Length == 2)
                        {
                            foreach (var property in DefaultProperty.Split(‘|‘))
                            {
                                if(control.GetType().GetProperty(property)!=null)
                                {
                                    bindProperty = property;
                                    break;
                                }
                            }
                        }
                        else if (tagInfoArr.Length == 3)
                        {
                            bindProperty = tagInfoArr[1];
                        }
                        else continue;

                        string propertyName = tagInfoArr[ta

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        329  2018-08-26 00:18  tview_v2\.git\config

     文件         73  2018-08-26 00:18  tview_v2\.git\description

     文件         23  2018-08-26 00:18  tview_v2\.git\HEAD

     文件        478  2018-08-26 00:18  tview_v2\.git\hooks\applypatch-msg.sample

     文件        896  2018-08-26 00:18  tview_v2\.git\hooks\commit-msg.sample

     文件       3327  2018-08-26 00:18  tview_v2\.git\hooks\fsmonitor-watchman.sample

     文件        189  2018-08-26 00:18  tview_v2\.git\hooks\post-update.sample

     文件        424  2018-08-26 00:18  tview_v2\.git\hooks\pre-applypatch.sample

     文件       1638  2018-08-26 00:18  tview_v2\.git\hooks\pre-commit.sample

     文件       1348  2018-08-26 00:18  tview_v2\.git\hooks\pre-push.sample

     文件       4898  2018-08-26 00:18  tview_v2\.git\hooks\pre-rebase.sample

     文件        544  2018-08-26 00:18  tview_v2\.git\hooks\pre-receive.sample

     文件       1492  2018-08-26 00:18  tview_v2\.git\hooks\prepare-commit-msg.sample

     文件       3610  2018-08-26 00:18  tview_v2\.git\hooks\update.sample

     文件      11579  2018-08-26 00:18  tview_v2\.git\index

     文件        240  2018-08-26 00:18  tview_v2\.git\info\exclude

     文件        182  2018-08-26 00:18  tview_v2\.git\logs\HEAD

     文件        182  2018-08-26 00:18  tview_v2\.git\logs\refs\heads\master

     文件        182  2018-08-26 00:18  tview_v2\.git\logs\refs\remotes\origin\HEAD

     文件       4012  2018-08-26 00:18  tview_v2\.git\objects\pack\pack-53cd1978e83da37a3d4b34eabbda43e714d251f5.idx

     文件    1118364  2018-08-26 00:18  tview_v2\.git\objects\pack\pack-53cd1978e83da37a3d4b34eabbda43e714d251f5.pack

     文件        114  2018-08-26 00:18  tview_v2\.git\packed-refs

     文件         41  2018-08-26 00:18  tview_v2\.git\refs\heads\master

     文件         32  2018-08-26 00:18  tview_v2\.git\refs\remotes\origin\HEAD

     文件        452  2018-08-26 00:51  tview_v2\.vs\TView\DesignTimeBuild\.dtbcache

    ..A..H.    102400  2018-08-29 22:54  tview_v2\.vs\TView\v15\.suo

     文件          0  2018-08-26 00:18  tview_v2\.vs\TView\v15\Server\sqlite3\db.lock

     文件       4096  2018-08-26 00:18  tview_v2\.vs\TView\v15\Server\sqlite3\storage.ide

     文件      32768  2018-08-29 21:33  tview_v2\.vs\TView\v15\Server\sqlite3\storage.ide-shm

     文件     972352  2018-08-29 21:34  tview_v2\.vs\TView\v15\Server\sqlite3\storage.ide-wal

............此处省略163个文件信息

评论

共有 条评论