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
1435
XamDataGrid HeaderPrefixArea Style issue
posted

Hi,

I have a style that inserts a Button in the HeaderPrefixArea and a behavior (with a Dependency Property) that I'm attaching to the Button.

I'm binding the  Dependency Property to the XamDataGrid. The issue is when I use the RelativeSource binding, the behavoir is throwing an exception. If I bind by ElementName it works.

The reason I want to use the RelativeSource is because I want this style to be in the App.xaml

Please see attached sample.

  <igDP:XamDataGrid.Resources>
                <Style TargetType="{x:Type igDP:HeaderPrefixArea}"
                       BasedOn="{x:Null}">
                    <Setter Property="Visibility"
                            Value="Visible" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type igDP:HeaderPrefixArea}">
                                <StackPanel Orientation="Horizontal"
                                            HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                                            VerticalAlignment="{TemplateBinding VerticalAlignment}">
                                    <Button Name="testButton"
                                            VerticalAlignment="Center"
                                            Height="25"
                                            Content="Click Me">
                                        <i:Interaction.Behaviors>
                                            <local:ButtonBehavior ParentDG="{Binding  ElementName=dataGrid}" />
                                            <!--<local:ButtonBehavior ParentDG="{Binding  RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:XamDataGrid}}}" />-->
                                        </i:Interaction.Behaviors>
                                    </Button>
                                </StackPanel>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </igDP:XamDataGrid.Resources>