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
425
AllowEdit and AllowAddNew with Binding
posted

i try to bind my "IsReadOnly"-Property to FieldSettings.AllowEdit and FieldLayoutSettings.AllowAddNew Property, with my own "OppositeNullableBoolConverter".

 

 <igDP:XamDataGrid xmlns:igDP="http://infragistics.com/DataPresenter"
                                    DataContext="{Binding Aktivitaet}"
                                    DataSource="{Binding DataContext.rsVerteiler, RelativeSource={RelativeSource Self}}"
                                    Height="127" Margin="161,326.723,19,0" Name="grd_Verteiler"
                                    VerticalAlignment="Top">
                    <igDP:XamDataGrid .FieldLayoutSettings>
                        <igDP:FieldLayoutSettings AllowAddNew="{Binding Path=DataContext.IsReadOnly,
                                                                Mode=OneWay,
                                                                RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}},
                                                                Converter={StaticResource localBoolToOppositeNullableBoolConverter}}" />
                    </igDP:XamDataGrid .FieldLayoutSettings>
                    <igDP:XamDataGrid .FieldSettings>
                        <igDP:FieldSettings AllowEdit="{Binding Path=DataContext.IsReadOnly,
                                                                Mode=OneWay,
                                                                RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}},
                                                                Converter={StaticResource localBoolToOppositeNullableBoolConverter}}" />
                    </igDP:XamDataGrid .FieldSettings>
                </igDP:XamDataGrid >

 

alternative binding:

<igDP:XamDataGrid xmlns:igDP="http://infragistics.com/DataPresenter"
                                    DataSource="{Binding Aktivitaet.rsVerteiler}"
                                    Height="127" Margin="161,326.723,19,0" Name="grd_Verteiler"
                                    VerticalAlignment="Top">
                    <igDP:XamDataGrid.FieldLayoutSettings>
                        <igDP:FieldLayoutSettings AllowAddNew="{Binding Path=Aktivitaet.IsReadOnly,
                                                                Mode=OneWay,
                                                                Converter={StaticResource localBoolToOppositeNullableBoolConverter}}" />
                    </igDP:XamDataGrid.FieldLayoutSettings>
                    <igDP:XamDataGrid.FieldSettings>
                        <igDP:FieldSettings AllowEdit="{Binding Path=Aktivitaet.IsReadOnly,
                                                                Mode=OneWay,
                                                                Converter={StaticResource localBoolToOppositeNullableBoolConverter}}" />
                    </igDP:XamDataGrid.FieldSettings>
                </igDP:XamDataGrid>

 

the binding to DataSource works fine but by the binding at AllowAddNew and AllowEdit i get this binding error at runtime:

Cannot find governing FrameworkElement or FrameworkContentElement for target element

what am I doing wrong?

thank you.

 

 

Parents
No Data
Reply
  • 9836
    Suggested Answer
    posted

    Hi,

    This error is usually thrown by the RelativeSource expression when the binding expression could not find an ancestor element in the visual tree - in your case I think this link of code is throwing the error:
    RelativeSource={RelativeSource AncestorType={x:Type igDP:XamDataGrid}}

    Note that the FieldSettings object is not in the visual tree so the syntax that you are using will not work at all. You can find more details about this limitation here. Also in order the AddNewRow to appear in the grid your collection should implement IBindingList interface (e.g. BindingList). I suggest you to add a reference to your viewmodel class in the view and use it as a StaticResource when binding the AllowEdit and AllowAddNew properties. I'm attaching a sample project so you can see this implementation.

    I hope this helps.

                                                                   

    WpfModelViewApplication1.zip
Children