Binding to static property

后端 未结 12 2395
夕颜
夕颜 2020-11-22 05:14

I\'m having a hard time binding a simple static string property to a TextBox.

Here\'s the class with the static property:



        
12条回答
  •  忘掉有多难
    2020-11-22 05:34

    Right variant for .NET 4.5 +

    C# code

    public class VersionManager
    {
        private static string filterString;
    
        public static string FilterString
        {
            get => filterString;
            set
            {
                if (filterString == value)
                    return;
    
                filterString = value;
    
                StaticPropertyChanged?.Invoke(null, FilterStringPropertyEventArgs);
            }
        }
    
        private static readonly PropertyChangedEventArgs FilterStringPropertyEventArgs = new PropertyChangedEventArgs (nameof(FilterString));
        public static event PropertyChangedEventHandler StaticPropertyChanged;
    }
    

    XAML binding (attention to braces they are (), not {})

    
    

提交回复
热议问题