B
B
BadCats2017-07-01 17:31:12
WPF
BadCats, 2017-07-01 17:31:12

Can't get dependency property value?

There is a class - describing the dependency property

namespace WpfApp1
{
    class BrushClass: InkCanvas
    {  
        public static   DependencyProperty BrushProperty;

       static  BrushClass()
        {
            BrushProperty = DependencyProperty.Register("BrushData",typeof(Brush),typeof(BrushClass));
        }

        public Brush BrushData
        {
            get { return (Brush)GetValue(BrushProperty); }
            set { SetValue(BrushProperty, value); }
        }
    }
}

- but when in another class - in the button handler - I try to get its values ​​- it doesn't see the DependencyProperty type field for the GetValue argument
private void Button_Click(object sender, RoutedEventArgs e)
        {
            Brush_Control.BrushData.SetCurrentValue(BrushProperty, 5); // не видит BrushProperty
          
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew K., 2017-07-01
@BadCats

BrushProperty is a static field and should be accessed accordingly

SetCurrentValue( BrushClass .BrushProperty, 5);

R
Roman, 2017-07-03
@yarosroman

so you just need Brush_Control.BrushData = 5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question