Wednesday, May 21, 2008

If you declare a read-only property as defined by the two ways below, you cannot bind a property to it by using IDE (database icon is not available in this case):

1.

private static DependencyProperty TextToDisplayProperty =

    DependencyProperty.Register("TextToDisplay", typeof(System.String), typeof(Activity1));

 

[Description("The text to output to the console")]

public string TextToDisplay

{

    get { return (string)base.GetValue(Activity1.TextToDisplayProperty); }

}

 

2.

 

private static DependencyProperty TextToDisplayProperty =

    DependencyProperty.Register("TextToDisplay", typeof(System.String), typeof(Activity1), new PropertyMetadata(DependencyPropertyOptions.ReadOnly));

 

[Description("The text to output to the console")]

public string TextToDisplay

{

    get { return (string)base.GetValue(Activity1.TextToDisplayProperty); }

    set { base.SetValue(Activity1.TextToDisplayProperty, value); }

}

 

Although there exists a crippled way to make it happen anyway here's the statement of the Microsoft Product Group :


"General guidance is that read only properties should not be bound. The UI allows it due to the bug. In dev10 we will fix this and it should no longer be possible through the designer, but probably still possible in code. Please avoid using this pattern. We know it works, but it’s not supported or tested. Anyway, we will not disable it in code, since we now know someone has a dependency on it."

.NET | WF
Latest Postings
Tags
History
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
License
Except where otherwise noted, content on this site is licensed under Creative Commons Attribution 3.0 Unported License:
Creative Commons Attribution 3.0 Unported License