惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
博客园 - 司徒正美
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
Y
Y Combinator Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
博客园_首页
Jina AI
Jina AI
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Vercel News
Vercel News
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
N
Netflix TechBlog - Medium
B
Blog
Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 阿冠

git报错unable to read tree xxxxxx socket tcp 报错误码 103/10053 原因 NuGet 未能为 SSL/TLS 安全通道建立信任关系 NuGet 未能为 SSL/TLS 安全通道建立信任关系 Visual Studio Font Cache 字体缓存路径下的文件太大了 ControlTemplate 中 Bingding 附加属性时需要加入 Path WPF使用第三方的字体(TTF文件) Base class for cloning an object in C# 关闭Windows 系统当前连接的Wifi以及判断物理\虚拟网卡,有线\无线网卡 - 阿冠 - 博客园 WPF 竖排文字 WPF 将DLL嵌入EXE文件(安装包) WPF 程序自删除(自毁)|卸载程序删除 WPF listbox UI虚拟化 记一次纠结Macbook 重装OS X的系统 指定的元素已经是另一个元素的逻辑子元素。请先将其断开连接。(解决问题总结) 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1 foreach---集合已修改;可能无法执行枚举操作。 判断s2是否能够被通过s1做循环移位(rotate)得到的字符串是否包含 多列转1列 SqlServer 实现oracle10g的 wmsys.wm_concat()--for xml path('')
WPF_View中控件使用单例ViewModel
阿冠 · 2015-03-12 · via 博客园 - 阿冠

一个View里面单独的一个控件需要一个ViewModel

这个ViewModel类 可以做成单例

 public class VMTest:Ad.Core.ViewModel.ViewModel
    {
       public static readonly VMTest instance = new VMTest();
       private VMTest()
       {
           MyProperty = new ObservableCollection<BrowseHistory> ();
          
       }
       
        public static VMTest GetInstance()
        {
            return instance;
        }

        /// <summary>
        /// 
        /// </summary>
        public ObservableCollection<BrowseHistory> MyProperty
        {
            get { return (ObservableCollection<BrowseHistory>)this.Property["MyProperty"]; }
            set { this.Property["MyProperty"] = value; }
        }
        public void Add(string id, string fileName)
        {
            BrowseHistory model = new BrowseHistory();
            model.Id = id;
            model.FileName = fileName;
            MyProperty.Add(model);
         }
    }

View Code

赋值

------------------

在需要的地方调用Add() ,给MyProperty赋值

使用

---------------

在View 里面的控件使用MyProperty 的话,

1.设置控件 DataContext, vm:为引用ViewModel类简写名。

DataContext="{x:Static vm:VMTest.instance}"

2. Binding 

Binding Property[MyProperty]