Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
Disable XamTextEditor Field conditionally using MVVM
posted

Hello Infragistics Team

I have a field in my XamDataGrid as shown below:

                            <igDP:Field Name="FieldName" Label="Field Name" Width="210" IsEnabled="{Binding IsFieldEnabled}">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings EditorType="{x:Type igEditors:XamTextEditor}" DataItemUpdateTrigger="OnCellValueChange">
                                        <igDP:FieldSettings.EditorStyle>
                                            <Style TargetType="{x:Type igEditors:XamTextEditor}">
                                                <Setter Property="IsEnabled" Value="{Binding IsFieldEnabled}" />
                                                <Setter Property="ValueConstraint">
                                                    <Setter.Value>
                                                        <igEditors:ValueConstraint MaxLength="16" />
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </igDP:FieldSettings.EditorStyle>
                                    </igDP:FieldSettings>
                                </igDP:Field.Settings>                               
                            </igDP:Field>

I'm unable to disable field conditionally using the property in the data model (MVVM pattern). I'm able to do this successfully in other grids that uses XamComboEditor instead of XamTextEditor. What am I doing wrong ?

Thanks

Shanmuga

  • 17475
    Offline posted

    Hello and thank you for posting! 

    As it seems from the provided code snippet you are trying to bind the IsEnabled field property to a property from the DataContext. Since the field is not a visual element it has no access to the DataContext and the binding will not work. Using a StaticResource can help you set the IsEnabled property based on a value in the ViewModel: IsEnabled="{Binding Source={StaticResource vm}, Path=IsFieldEnabled}"

    Let me know if you have any questions.