Answer the question
In order to leave comments, you need to log in
What am I doing wrong when creating dependency property in wpf?
I have a MainWindow.XAML file
- in which I create my own control called ControlBrush
<ControlBrush:MyBrushClass
x:Name="NewBackground"
CanvasBrushCLR="{Binding ElementName=canvas1, Path=Background }">
</ControlBrush:MyBrushClass>
xmlns:ControlBrush="clr-namespace:WpfApp1"
public double CanvasBrushCLR
{
get { return (double)GetValue(CanvasBrushProperty); }
set { SetValue(CanvasBrushProperty, value); }
}
public static DependencyProperty CanvasBrushProperty;//имя поля
static MyBrushClass()
{
CanvasBrushProperty = DependencyProperty.Register("CanvasBrushCLR", typeof(double ), typeof(MyBrushClass));
}
//CanvasBrushCLR -ИМЯ CLR обвертки
//typeof(Color) - тип свойства зависимости
//typeof(MyBrushClass) - класс в котором регистрируется свойство зависимости
MyBrushClass mb;
private void button2_Click(object sender, RoutedEventArgs e)
{
mb = new MyBrushClass();
canvas1.Background.Opacity = mb.CanvasBrushCLR; //обрабатываем binding
}
private void button1_Click(object sender, RoutedEventArgs e)
{
mb = new MyBrushClass();
mb.CanvasBrushCLR = (double)Convert.ToInt32( TB1.GetLineText(0));
}
Cannot set object property '#FFFFFFFF' because it is in read-only state- although both Opacity and CanvasBrushCLR - have get and set access methods.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question