Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7569591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:12:16+00:00 2026-05-30T15:12:16+00:00

I’m using this control Here to be able to host Table that can bind

  • 0

I’m using this control Here to be able to host Table that can bind to a list and to generate rows accordingly, that worked really good, however the table just doesn’t appear when printing to an XPS or PDF files, it does appear on the FlowDocument but it prints as blank , I tried changing the colors of Background and Foreground with no success , any suggestions ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T15:12:17+00:00Added an answer on May 30, 2026 at 3:12 pm

    I have just successfully implemented that example (Create Flexible UIs With Flow Documents And Data Binding) and did experience the same problem as you.

    The problem was that the DataContext for the BindableRun is not being set correctly. As explained in the article you need to fix-up the context (using the FixupDataContext helper method), set the DataContext for the FrameworkContentElement, and clear the context that you previous ‘fixed’ up (using the UnFixupDataContext helper method). The order of execution of these statements is critical. Re-read the article again and make sure you understand it; I had to re-read it several times and study the code to truly understand what he was talking about.

    I have taken the implementation one step further and added support for data binding other elements in the TableCell. The changes comprises of using an attached property to identify elements that have their DataContext ‘fixed’ and then expanding the on the helper methods to also work against FrameworkElements in addition the FrameworkContentElements.

    HTH,

    Edit:

    public static class DataContextHelper
    {
    
        #region UseAncestorDataContext
    
        public static readonly DependencyProperty UseAncestorDataContextProperty = DependencyProperty.RegisterAttached("UseAncestorDataContext", typeof(bool), typeof(DataContextHelper),
                                                                                        new FrameworkPropertyMetadata(false, DataContextHelper.OnUseAncestorDataContextChanged));
    
        public static bool GetUseAncestorDataContext(DependencyObject d)
        {
            return (bool)d.GetValue(UseAncestorDataContextProperty);
        }
    
        public static void SetUseAncestorDataContext(DependencyObject d, bool value)
        {
            d.SetValue(UseAncestorDataContextProperty, value);
        }
    
        private static void OnUseAncestorDataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
                UseAncestorDataContext(d);
        }
    
        #endregion
    
        /// <summary>
        /// If you use a Bindable flow document element more than once, you may encounter a "Collection was modified" 
        /// exception. The error occurs when the binding is updated because of a change to an inherited dependency 
        /// property. The most common scenario is when the inherited DataContext changes. It appears that an inherited 
        /// properly like DataContext is propagated to its descendants. When the enumeration of descendants gets to 
        /// a Bindable, the dependency properties of that element change according to the new DataContext, which change 
        /// the (non-dependency) properties. However, for some reason, changing the flow content invalidates the enumeration 
        /// and raises an exception.
        /// </summary>        
        public static void UseAncestorDataContext(DependencyObject element)
        {            
            if (element is FrameworkContentElement)
            {
                FrameworkContentElement contentElement = (FrameworkContentElement)element;
                Binding binding = new Binding(FrameworkContentElement.DataContextProperty.Name);
                binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FrameworkElement), 1);
                contentElement.SetBinding(FrameworkContentElement.DataContextProperty, binding);
            }
            else if (element is FrameworkElement)
            {
                FrameworkElement frameworkElement = (FrameworkElement)element;
                Binding binding = new Binding(FrameworkElement.DataContextProperty.Name);
                binding.RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(FrameworkElement), 1);
                frameworkElement.SetBinding(FrameworkContentElement.DataContextProperty, binding);
            }
        }
    
        public static void ClearDataContextBinding(DependencyObject d)
        {
            while (RestoreDataContextRecursive(d));            
        }
    
        private static bool RestoreDataContextRecursive(DependencyObject d)
        {            
            if (d is FrameworkContentElement && GetUseAncestorDataContext(d))
            {
                Binding binding = BindingOperations.GetBinding(d, FrameworkContentElement.DataContextProperty);
                if (binding != null && binding.Path != null && binding.Path.Path == FrameworkContentElement.DataContextProperty.Name
                    && binding.RelativeSource != null && binding.RelativeSource.Mode == RelativeSourceMode.FindAncestor && binding.RelativeSource.AncestorType == typeof(FrameworkElement) && binding.RelativeSource.AncestorLevel == 1)
                {
                    BindingOperations.ClearBinding(d, FrameworkContentElement.DataContextProperty);
                    return true;
                }
            }
            else if (d is FrameworkElement && GetUseAncestorDataContext(d))
            {
                Binding binding = BindingOperations.GetBinding(d, FrameworkElement.DataContextProperty);
                if (binding != null && binding.Path != null && binding.Path.Path == FrameworkElement.DataContextProperty.Name
                    && binding.RelativeSource != null && binding.RelativeSource.Mode == RelativeSourceMode.FindAncestor && binding.RelativeSource.AncestorType == typeof(FrameworkElement) && binding.RelativeSource.AncestorLevel == 1)
                {
                    BindingOperations.ClearBinding(d, FrameworkElement.DataContextProperty);
                    return true;
                }
            }
    
            // As soon as we have disconnected a binding, return. Don't continue the enumeration, since the collection may have changed
            foreach (object child in LogicalTreeHelper.GetChildren(d))
            {
                if (child is DependencyObject && RestoreDataContextRecursive((DependencyObject)child))
                    return true;
            }
    
            return false;
        }
    
    }
    

    Usage

     <DataTemplate x:Key="PercentCellTemplate">
            <documents:ContentFragment>
                <TableCell Style="{StaticResource TableCellStyle}" BorderThickness="0,0,1,0"> 
                    <Paragraph>
                        <Rectangle Width="14" Height="14" VerticalAlignment="Center" Margin="0,6,0,0" Fill="{Binding Path=Result, Mode=OneWay, Converter={StaticResource MappingConverterResultEnumToIconResource}}" 
                                   documents:DataContextHelper.UseAncestorDataContext="True"/>
                        <documents:DocumentRun Style="{StaticResource ReportDocument_NormalRunStyle}" Text="{Binding Path=Percent, Mode=OneWay, StringFormat={}{0:0.000}%}" 
                                               BaselineAlignment="Center" documents:DataContextHelper.UseAncestorDataContext="True" />
                    </Paragraph>
                </TableCell>
            </documents:ContentFragment>
        </DataTemplate>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.