अद्यतन मैं ऐसे WPF बाइंडिंग कोड है:Oneway बाध्यकारी बंद हो जाता है काम करने के बाद लक्ष्य मैन्युअल
TestModel source = new TestModel();
TestModel target = new TestModel();
Bind(source, target, BindingMode.OneWay);
source.Attribute = "1";
AssertAreEqual(target.Attribute, "1");
target.Attribute = "foo";
source.Attribute = "2";
AssertAreEqual(target.Attribute, "2");
दूसरे दावे विफल रहता है! यह मेरे लिए अजीब लगता है।
इसके अलावा, मैंने 'वनवे' के बजाय 'वनवेटसोर्स' की कोशिश की, और सभी काम अपेक्षित थे।
Bind(source, target, BindingMode.OneWayToSource);
target.Attribute = "1";
AssertAreEqual(source.Attribute, "1");
source.Attribute = "foo";
target.Attribute = "2";
AssertAreEqual(source.Attribute, "2");
अन्य विवरण:
void Bind(TestModel source, TestModel target, BindingMode mode)
{
Binding binding = new Binding();
binding.Source = source;
binding.Path = new PropertyPath(TestModel.AttributeProperty);
binding.Mode = mode;
BindingOperations.SetBinding(target, TestModel.AttributeProperty, binding);
}
class TestModel : DependencyObject
{
public static readonly DependencyProperty AttributeProperty =
DependencyProperty.Register("Attribute", typeof(string), typeof(TestModel), new PropertyMetadata(null));
public string Attribute
{
get { return (string)GetValue(AttributeProperty); }
set { SetValue(AttributeProperty, value); }
}
}
क्या मेरी कोड के साथ गलत क्या है?
यह समझता है कि स्टाइल सेट स्टाइल शैली टेम्पलेट मान को ओवरराइड कर देगी, और स्थानीय मान स्टाइल वैल्यू को ओवरराइड करेगा, लेकिन मेरे पास इसका कुछ भी नहीं है। तो सुनिश्चित नहीं है कि यह इस मुद्दे को समझाता है ... किसी भी तरह से धन्यवाद। – alex2k8
इसके अलावा, यह OneWay और OneWayToSource – alex2k8