خرید بک لینک

Vote count: 0

I'm trying to create a Label in runtime and coect it's Content property to other TextBox control which is inside my UserControl called MyLabelSettings.

This is what i got so far:

Label currCtrl = new Label();
MyLabelSettings currCtrlProperties = new MyLabelSettings();

// Bindings to properties
Binding binding = new Binding();
binding.Source = currCtrlProperties.textBox_Text.Text;
binding.Path = new PropertyPath(Label.VisibilityProperty);
BindingOperations.SetBinding(currCtrl.Content, Label.ContentProperty, binding);

The last row shows an error which I did not figure out how to solve:

The best overloaded method match for 'System.Windows.Data.BindingOperations.
SetBinding(System.Windows.DependencyObject, System.Windows.DependencyProperty,
System.Windows.Data.BindingBase)' has some invalid arguments

I have in MyLabelSettings the implementation of INotifyPropertyChanged which has the following code when the TexBox.Text changes

private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
        InvokePropertyChanged(new PropertyChangedEventArgs("TextChanged"));
    }

Is there a better way to bind these 2? or am i doing something wrong in this one?

Thanks!

asked 54 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 22 فروردين 1395 ساعت: 23:45

صفحه بندی