Custom WPF Binding

前端 未结 3 803
离开以前
离开以前 2021-01-21 02:55

I have a custom MarkupExtension that simulates binding. It works well in normal assignments but when used in Style Setters, for example:



        
3条回答
  •  有刺的猬
    2021-01-21 03:27

    Kind of guessing, but it's likely because the XAML compiler has special built-in support for the Binding class, allowing its usage in this scenario (and others). The Binding class is also a MarkupExtension, but unfortunately it seals its implementation of ProvideValue().

    That said, you might just get away with this:

    public class MyBinding : Binding
    {
        private object value;
    
        public object Value
        {
            get { return this.value; }
            set
            {
                this.value = value;
                this.Source = value;
            }
        }
    }
    

    Since ProvideValue will return the Binding instance anyway.

提交回复
热议问题