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
180
xamDataChart binding error generated from Infragistics theme
posted

1460.TestWPFApp.zip

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Controls.Charts.FinancialLegend', AncestorLevel='1''. BindingExpression:(no path); DataItem=null; target element is 'ContentControl' (Name='financialLegendContent'); target property is 'NoTarget' (type 'Object')


I am getting the above binding error only when I have assigned an Infragistics theme using theme manager.

ThemeManager.ApplicationTheme = new Office2010BlueNew();

I have tracked the issue down to the following code in xamdatachart.xaml for the decompiled theme but I don't know how to fix it. The error seems to be generated in the ContentControlStyle DataTrigger binding.

 <DataTemplate x:Key="LegendItemTemplate">
     <Grid>
         <StackPanel Margin="{StaticResource LegendItemMargin}" Orientation="Horizontal">
             <StackPanel.Style>
                 <Style TargetType="StackPanel">
                     <Style.Triggers>
                         <DataTrigger Binding="{Binding Visibility, ElementName=financialLegendContent}" Value="Visible">
                             <Setter Property="Visibility" Value="Collapsed" />
                         </DataTrigger>
                         <DataTrigger Binding="{Binding Series.Visibility}" Value="Collapsed">
                             <Setter Property="Visibility" Value="Collapsed" />
                         </DataTrigger>
                     </Style.Triggers>
                 </Style>
             </StackPanel.Style>
             <ContentPresenter
                 Margin="{StaticResource LegendItemBadgeMargin}"
                 Content="{Binding}"
                 ContentTemplate="{Binding Series.LegendItemBadgeTemplate}" />
             <ContentControl
                 FontFamily="{StaticResource FinancialLegendFontFamily}"
                 FontSize="{Binding Series.ActualLegend.ItemsFontSize}"
                 FontStretch="{Binding Series.ActualLegend.ItemsFontStretch}"
                 FontStyle="{Binding Series.ActualLegend.ItemsFontStyle}"
                 FontWeight="{Binding Series.ActualLegend.ItemsFontWeight}"
                 Foreground="{Binding Series.ActualLegend.ItemsForeground}">
                 <ContentPresenter Content="{Binding Series.Title, TargetNullValue=Series Title}" />
             </ContentControl>
         </StackPanel>
         <ContentControl
             x:Name="financialLegendContent"
             FontFamily="{Binding Series.ActualLegend.ItemsFontFamily}"
             FontSize="{Binding Series.ActualLegend.ItemsFontSize}"
             FontStretch="{Binding Series.ActualLegend.ItemsFontStretch}"
             FontStyle="{Binding Series.ActualLegend.ItemsFontStyle}"
             FontWeight="{Binding Series.ActualLegend.ItemsFontWeight}"
             Foreground="{Binding Series.ActualLegend.ItemsForeground}">
             <ContentControl.Style>
                 <Style TargetType="ContentControl">
                     <Style.Triggers>
                         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:FinancialLegend}}" Value="{x:Null}">
                             <Setter Property="Visibility" Value="Collapsed" />
                         </DataTrigger>
                         <DataTrigger Binding="{Binding Series.Visibility}" Value="Collapsed">
                             <Setter Property="Visibility" Value="Collapsed" />
                         </DataTrigger>
                     </Style.Triggers>
                 </Style>
             </ContentControl.Style>
             <Border
                 Margin="{StaticResource FinancialLegendMargin}"
                 Padding="{StaticResource FinancialLegendPadding}"
                 Background="{StaticResource FinancialLegendBackgroundBrush}">
                 <StackPanel Orientation="Horizontal">
                     <ContentPresenter
                         Margin="{StaticResource LegendItemBadgeMargin}"
                         Content="{Binding}"
                         ContentTemplate="{Binding Series.LegendItemBadgeTemplate}" />
                     <ContentControl FontSize="{StaticResource ChartSmallFontSize}" Foreground="{StaticResource ForegroundBrush}">
                         <ContentPresenter Content="{Binding Series.Title, TargetNullValue=Series Title}" />
                     </ContentControl>
                     <TextBlock
                         FontSize="{StaticResource ChartSmallFontSize}"
                         Foreground="{StaticResource ForegroundBrush}"
                         Text=": "
                         Visibility="{Binding Visibility, ElementName=finalValue}" />
                     <TextBlock
                         x:Name="finalValue"
                         FontSize="{StaticResource ChartSmallFontSize}"
                         FontWeight="{StaticResource FinancialLegendFinalValueWeight}"
                         Foreground="{StaticResource ForegroundBrush}"
                         Text="{Binding Series.FinalValue, StringFormat={}{0:0.00}}">
                         <TextBlock.Style>
                             <Style TargetType="TextBlock">
                                 <Style.Triggers>
                                     <Trigger Property="Text" Value="NaN">
                                         <Setter Property="Visibility" Value="Collapsed" />
                                     </Trigger>
                                 </Style.Triggers>
                             </Style>
                         </TextBlock.Style>
                     </TextBlock>
                     <TextBlock
                         FontSize="{StaticResource ChartSmallFontSize}"
                         Foreground="{StaticResource ForegroundBrush}"
                         Text="{Binding Series.PercentChange, StringFormat=' ({0:0.00}%)'}">
                         <TextBlock.Style>
                             <Style TargetType="TextBlock">
                                 <Style.Triggers>
                                     <Trigger Property="Text" Value=" (NaN%)">
                                         <Setter Property="Visibility" Value="Collapsed" />
                                     </Trigger>
                                 </Style.Triggers>
                             </Style>
                         </TextBlock.Style>
                     </TextBlock>
                 </StackPanel>
             </Border>
         </ContentControl>
     </Grid>
 </DataTemplate>

Parents
  • 34830
    Verified Answer
    Offline posted

    Hello Bob,

    I have been investigating into the behavior you are seeing, and I have reproduced it. It appears that this only happens with the themes, as there is an issue with the themes versus the default style of the control. Specifically, it appears to be the binding of this DataTrigger:

    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:FinancialLegend}}" Value="{x:Null}">

    If you are not using the XamFinancialChart, this will cause a binding error. This differs from the default style of the XamDataChart, as the default style’s binding is this instead:

    <DataTrigger Binding="{Binding Series.IsActualLegendFinancial}" Value="False">

    Unfortunately, the best workaround I can offer in this case is to bring in the LegendItemTemplate and its dependencies into your application and change this and apply it to any series that you are not writing a custom LegendItemTemplate for (or remove the DataTrigger if you are not using the XamFinancialChart).

    It is worth noting though, that these binding errors will not break your application unless you explicitly tell Visual Studio to break on System.Windows.Data errors in your Exception Settings, but still, this should not be happening, and I have logged a bug for it in our internal tracking system so we can track it and apply the binding mentioned above to all of the themes. This issue has an ID of 28801, and I will be linking it to a private support case that I have created for you so you can be notified of a fix when it becomes available. This support case has an ID of C-00234733, and you can access it after signing into your account, here: https://account.infragistics.com/support-cases.

    Please let me know if you have any other questions or concerns on this matter.

Reply Children
No Data