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
125
Binding TextField.Label to ancestor Datacontext property
posted

Hello,

On a usercontrol, I have a xamdatagrid.

the DataSource of this dataGrid refers to a property of the userControl dataContext.

In this datagrid, I have a column (define by TextField) where the label depends on a property of the userControl dataContext.

I have tryed many solutions but no one do the tricks. I show you some of my trys.

<igDp:TextField

Name="MySpecificColumn"

Label="{Binding DataContext.SpecificColumnHeaderDisplay , ElementName=UserControl}" //x:name="UserControl" define on the UserControl

Label="{Binding DataContext.SpecificColumnHeaderDisplay, RelativeSource = {RelativeSource FindAncestor, AncestorType={x:Type v:MyView}} // xmlns:v= namespace of my userControl

/>

Thanks you in advance for your helps

  • 1560
    Offline posted
    Hello Christophe,
    Thank you for the code-snippet you have provided.

    Fields are not part of the visual tree of the XamDataGrid and this might be the reason why none of the suggested way for binding is not working as per your expectation. However, the label text property of your view model  can be bound in the LabelPresenter using DataTemplate:
     

    <igWPF:TextField Name="Name" >                            
                                <igWPF:TextField.Settings>
                                    <igWPF:FieldSettings>
                                        <igWPF:FieldSettings.LabelPresenterStyle>
                                            <Style TargetType="{x:Type igWPF:LabelPresenter}">                                                                                                            
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <DataTemplate>
                                                            <TextBlock Text="{Binding DataContext.SomeText, ElementName=uc}"/>
                                                        </DataTemplate>
                                                    </Setter.Value>
                                              </Setter>
                                            </Style>
                                        </igWPF:FieldSettings.LabelPresenterStyle>
                                    </igWPF:FieldSettings>
                                </igWPF:TextField.Settings>
        </igWPF:TextField>

    I have attached a sample application, that uses the approach from above.
    If you require any further assistance on the matter, please let me know.
    Sincerely,

    Teodosia Hristodorova
    Associate Software Developer
    Infragistics