IsReadOnly binding to VMs property

7 posts, 0 answers
  1. Vitalij
    Vitalij avatar
    35 posts
    Member since:
    Dec 2010

    Posted 20 Jun 2013 Link to this post

    Hi

    I want to achieve some functionality. I have searched the web for over 4 days to find a solution but no luck at all. I am using Q2 2013 WPF components.

    I have a MainVM that's creates and binds various VMs (one at a time). One of the VM is personVM with 3 properties Name, IsValid and lets say Age. I have implemented the IDataErrorInfo interface and it is working with PropertyGrid as expected. I have the same personVM for creating and editing person. The Name is required property and I want to force the user to set the Name before setting the Age. Best solution would be to disable Age definition and enable it when user sets the Name. I tried to set Age property definition IsReadOnly property to bind to IsValid, but it gave me an error 2 cannot find governing frameworkelement... I found an online help that says I need to explicitly define Source property of IsReadOnly property. How can I achieve that?? Or do you know better solution?? I tried also to disable AutoGeneratedPropertyDefinitions and create custom edit template with TextBox for Age and bind the TextBoxs IsEnabled to IsValid, but it is always enabled. Does the property definition override the enabled property of the textbox?? 

    Thanks 

    Vitalij
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 20 Jun 2013 Link to this post

    Hello,

     PropertyDefinitions are not part of the logical tree (they define a set of rules that is used by RadPropertyGrid to generate the respective fields and editors). So that, they neither have a DataContext, nor can use ElementName and RelativeSource bindings. You can set the Binding source to be your ViewModel and bind the IsReadOnly property to a property of the ViewModel. The generated editors has their ReadOnly (for TextBox) and IsEnabled (for other controls) bound, so that it is not recommended to do so. In case you need additional assistance, you can send a sample project that illustrates your scenario. We will do our best to debug it on our side and send you a modified version.

    Regards,
    Ivan Ivanov
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Vitalij
    Vitalij avatar
    35 posts
    Member since:
    Dec 2010

    Posted 26 Jun 2013 Link to this post

    Hi Ivan

    I have prepared simple example. It demonstrate the functionality I want to implement. There are 3 VMs. One MainVm, PersonVM and ProductVM. MainVm is controlling the other two. Each PersonVM and ProductVM implements IDataErrorInfo to check validity of data. Everything works well but I cant bind the IsReadonly property of PropertyDefinition to hide the controls on validation error.

    I ran into a trouble to attach zip file with the project. The only allowed extensions are jpg, jpeg, gif and png. How can I send you the project??

    Vitalij
  5. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 01 Jul 2013 Link to this post

    Hi,

     Please excuse me for the delayed reply. You can send us a support ticket. You can upload *.zip files (up to 20 MB) there.

    Regards,
    Ivan Ivanov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Mikhail
    Mikhail avatar
    5 posts
    Member since:
    Sep 2013

    Posted 17 Oct 2013 Link to this post

    Hi Ivan,

    My problem is similar. I need to achieve behavoir when several properties in the PropertyGrid are enabled/disabled depending on another property value - of the same object. I use one instance of RadPropertyGrid for a lot of types in my application, so it's easier for me to use auto-generated PropertyDefinitions. 

    I'm trying to solve the problem using DataTemplate with control's IsEnabled property binding - it's more useful than PropertyDefinition IsReadOnly property, because I can bind both Text and IsEnabled properties to the same ViewModel object (I have many viewmodel types and several instances of each viewmodel type in common case).

    And it almost works, but... When I use auto-generated PropertyDefinition instance and set DataTemplate in RadPropertyGrid_AutoGeneratingPropertyDefinition handler, it doesn't work - the control in my template is always enabled. But if I use a PropertyDefinition instance, manually written in xaml, it works. 

    So, the problem is - how to make this scheme working with auto-generated PropertyDefinitions. Or maybe you would suppose another workaround. 

    Thank in advance,
    Mikhail S. Seliverstov
  7. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 22 Oct 2013 Link to this post

    Hi,

    May I ask you whether you are using FrameworkElementFactory, or templates that are defined in XAML? If you would like to share some more information on the whole idea, I will try to prepare a sample project for you. Thank you.

    Regards,
    Ivan Ivanov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. Mikhail
    Mikhail avatar
    5 posts
    Member since:
    Sep 2013

    Posted 22 Oct 2013 Link to this post

    Hi,

    Sorry, that was my own mistake, I've already managed it. The difference was not in auto-generated or declared-in-xaml PropertyDefinition using, but in IsEnabled binded property location. 

    If I use 

    <Grid IsEnabled="{Binding...}">
    <CheckBox IsChecked="{Binding...}"/>
    </Grid>

    it is OK,

    but when it is 

    <CheckBox IsChecked="{Binding...}" IsEnabled="{Binding...}"/>

    it doesn't work because PropertyDefiniiton's IsReadOnly overrides IsEnabled.  

Back to Top
UI for WPF is Visual Studio 2017 Ready