WPF绑定静态字典中指定对象的属性

WPF绑定静态字典中指定对象的属性

在此记录一下在开发过程中遇到的绑定全局静态字典特定对象的属性问题

1.创建一个对象
public class ConnectInfo:NotifyBase
    {
        private bool isConnect;

        public bool IsConnect
        {
            get { return isConnect; }
            set { isConnect = value; OnPropertyChanged(nameof(IsConnect)); }
        }

    }
2.创建全局静态变量
public class GlobalVaribales
{
	public static ConcurrentDictionary Varibales { get; set; } = new ConcurrentDictionary();
}
3.添加键值对到字典中
GlobalVariables.Varibales.TryAdd("num1", new Models.ConnectInfo() { IsConnect = false });
GlobalVariables.Varibales.TryAdd("num2", new Models.ConnectInfo() { IsConnect = true });
4.xaml中绑定对象属性

		
            
                
                    
                
            
        


完成!

你可能感兴趣的:(c#,开发语言,wpf)