IsReadOnly binding VM's property

2 posts, 1 answers
  1. Ye HaoChen
    Ye HaoChen avatar
    27 posts
    Member since:
    Nov 2009

    Posted 24 Feb 2014 Link to this post

    I bound IsReadOnly with VM's property.
    Code like this, but it's not working.

    DbIsReadOnly is VM's property.

    <telerik:PropertyDefinition Binding="{Binding Path=Host,Mode=TwoWay}" GroupName="dbSquidPorperties" DisplayName="{DynamicResource IP}" IsReadOnly="{Binding DataContext.DbIsReadOnly,RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"    OrderIndex="0"/>
  2. Answer
    Ivan Ivanov
    Ivan Ivanov avatar
    1116 posts

    Posted 27 Feb 2014 Link to this post


    PropertyDefinition derives from DependencyObject, so that it supports data binding. However, it does not derive from FrameworkElement, and it does not have DataContext. Moreover, it is not a visual element, so you cannot use ElementName and RelativeSource bindings. The only way to bind some of its properties is to expose the source explicitly. For instance:
    <telerik:PropertyDefinition Binding="{Binding Path=Host,Mode=TwoWay}"GroupName="dbSquidPorperties" DisplayName="{DynamicResource IP}" IsReadOnly="{Binding DbIsReadOnly,Source={StaticResource MyViewModel}}"    OrderIndex="0"/>

    Ivan Ivanov
  3. DevCraft banner
Back to Top