Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在代码隐藏中绑定静态属性_C#_Wpf_Xaml_Binding - Fatal编程技术网

C# 在代码隐藏中绑定静态属性

C# 在代码隐藏中绑定静态属性,c#,wpf,xaml,binding,C#,Wpf,Xaml,Binding,我试图遵循这一点,唯一的区别是我在代码隐藏中创建和绑定控件。 不幸的是,它不起作用。以下是我的示例代码: public partial class ShellWindow { private static Visibility progressbarVisibility = Visibility.Collapsed; public static Visibility ProgressbarVisibility { get { retu

我试图遵循这一点,唯一的区别是我在代码隐藏中创建和绑定控件。 不幸的是,它不起作用。以下是我的示例代码:

 public partial class ShellWindow
 {
      private static Visibility progressbarVisibility = Visibility.Collapsed;
      public static Visibility ProgressbarVisibility
      {
           get { return progressbarVisibility; }
           set
           {
               if (progressbarVisibility == value) return;
               progressbarVisibility = value;
               RaiseStaticPropertyChanged("ProgressbarVisibility");
           }
      }
      public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;
      public static void RaiseStaticPropertyChanged(string propName)
      {
           EventHandler<PropertyChangedEventArgs> handler = StaticPropertyChanged;
           if (handler != null)
               handler(null, new PropertyChangedEventArgs(propName));
     }
}
我想我遗漏了什么,但我不确定我错在哪里。
任何帮助都会很好。

文章说要使用:

{Binding (local:Repository.Color)}
由于
local:
在XAML文件之外没有任何意义,因此我认为不可能用字符串构造绑定

您还可以为
Binding.Path
属性分配一个属性,并接受
PropertyInfo
。要使用此构造函数,需要以标记化格式指定路径字符串(如上所述)。因此:


文章说使用:

{Binding (local:Repository.Color)}
由于
local:
在XAML文件之外没有任何意义,因此我认为不可能用字符串构造绑定

您还可以为
Binding.Path
属性分配一个属性,并接受
PropertyInfo
。要使用此构造函数,需要以标记化格式指定路径字符串(如上所述)。因此:

var propertyInfo = typeof(ShellWindow).GetProperty("ProgressbarVisibility");
var propertyPath = new PropertyPath("(0)", propertyInfo);
var binding = new Binding() { Path = propertyPath, Mode = BindingMode.TwoWay };