OneWayToSource के लिए कुछ शोध परिणाम ...
विकल्प # 1.
// Control definition
public partial class FlagThingy : UserControl
{
public static readonly DependencyProperty IsModifiedProperty =
DependencyProperty.Register("IsModified", typeof(bool), typeof(FlagThingy), new PropertyMetadata());
}
<controls:FlagThingy x:Name="_flagThingy" />
// Binding Code
Binding binding = new Binding();
binding.Path = new PropertyPath("FlagIsModified");
binding.ElementName = "container";
binding.Mode = BindingMode.OneWayToSource;
_flagThingy.SetBinding(FlagThingy.IsModifiedProperty, binding);
विकल्प # 2
// Control definition
public partial class FlagThingy : UserControl
{
public static readonly DependencyProperty IsModifiedProperty =
DependencyProperty.Register("IsModified", typeof(bool), typeof(FlagThingy), new PropertyMetadata());
public bool IsModified
{
get { return (bool)GetValue(IsModifiedProperty); }
set { throw new Exception("An attempt ot modify Read-Only property"); }
}
}
<controls:FlagThingy IsModified="{Binding Path=FlagIsModified,
ElementName=container, Mode=OneWayToSource}" />
विकल्प # 3 (यह सच है केवल पढ़ने के लिए निर्भरता संपत्ति)
System.ArgumentException: 'IsModified' संपत्ति नहीं किया जा सकता डेटा-बाउंड।
// Control definition
public partial class FlagThingy : UserControl
{
private static readonly DependencyPropertyKey IsModifiedKey =
DependencyProperty.RegisterReadOnly("IsModified", typeof(bool), typeof(FlagThingy), new PropertyMetadata());
public static readonly DependencyProperty IsModifiedProperty =
IsModifiedKey.DependencyProperty;
}
<controls:FlagThingy x:Name="_flagThingy" />
// Binding Code
Same binding code...
परावर्तक जवाब देता है:
internal static BindingExpression CreateBindingExpression(DependencyObject d, DependencyProperty dp, Binding binding, BindingExpressionBase parent)
{
FrameworkPropertyMetadata fwMetaData = dp.GetMetadata(d.DependencyObjectType) as FrameworkPropertyMetadata;
if (((fwMetaData != null) && !fwMetaData.IsDataBindingAllowed) || dp.ReadOnly)
{
throw new ArgumentException(System.Windows.SR.Get(System.Windows.SRID.PropertyNotBindable, new object[] { dp.Name }), "dp");
}
....
के लिए विशिष्ट है लेकिन आप एक रीड ओनली संपत्ति के मूल्य निर्धारित कर सकते हैं? – idursun
आप नहीं कर सकते। यह भी नहीं है कि मैं क्या हासिल करने की कोशिश कर रहा हूं। मैं संपत्ति 'फ्लैगआईजोडिफाइड' को रीडराइट करने के लिए रीडोनली प्रॉपर्टी 'IsModified' से प्राप्त करने का प्रयास कर रहा हूं। – Inferis
अच्छा सवाल। आपका कामकाज केवल तभी काम करता है जब कंटेनर एक निर्भरता ऑब्जेक्ट है और फ्लैगआईएसमोडिफाइड एक निर्भरता प्रॉपर्टी है। –