Quantcast
Channel: Silverlight 5 forum
Viewing all articles
Browse latest Browse all 1083

Problem with RelativeSource Binding and Silverlight printing

$
0
0

Hi everyone and thank you in advance for taking a look at my problem.

I'm trying to create a solution to print reports in silverlight and im facing a few difficulties.
I'm using this project http://silverlightreporting.codeplex.com/ which fits my needs perfectly.

This solution uses DataTemplates ( HeaderTemplate, ItemTemplate and FooterTemplate) to display the data you want to print and a Report control to create your pages.

HeaderTemplate's and FooterTemplate's DataContext is the Report Control, and ItemTemplate's DataContext is my data.

My ItemTemplate looks like this:

<DataTemplate x:Key="PageItemDataTemplate"><Grid HorizontalAlignment="Stretch" Margin="5 0 0 20"><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition Width="200" /><ColumnDefinition Width="200" /><ColumnDefinition Width="150" /><ColumnDefinition Width="150" /></Grid.ColumnDefinitions><TextBlock Text="{Binding Path=AlarmName, StringFormat='\{0}, '}" FontWeight="Bold" /><TextBlock Grid.Column="1" Text="{Binding Path=Type}" TextAlignment="Center" /><TextBlock Grid.Column="2" Text="{Binding Path=State}" TextAlignment="Right" Visibility="{Binding Path=DataContext.StateVisibility, RelativeSource={RelativeSource AncestorType=StackPanel}}"/><TextBlock Grid.Column="3" Text="{Binding Path=Device}" TextAlignment="Right"/><StackPanel Grid.Row="1" Orientation="Horizontal" Grid.ColumnSpan="4"><TextBlock Text="Event Description: " /></StackPanel><TextBlock Grid.Row="2" Grid.ColumnSpan="4" TextWrapping="Wrap" Text="{Binding Path=ReviewComments}" /></Grid></DataTemplate>

I'm binding one of my Textblock visibility to a property in my Report Control and it works fine.
Problems start when i try to print.

The printing function looks like this:

private void PrintDocumentPrintPageHandler(object sender, PrintPageEventArgs e)
        {

            if (_pageTreeIndex == 0)
            {
                BuildReport(e.PrintableArea);
                TotalPageCount = _pageTrees.Count;
                CurrentPageNumber = 0;
            }

            if (_pageTrees.Count > 0)
            {
                CurrentPageNumber++;
                e.PageVisual = _pageTrees[_pageTreeIndex];
            }

            e.HasMorePages = _pageTreeIndex < _pageTrees.Count -1;

            _pageTreeIndex++;
        }

_PageTrees is a list of UIElements which contains all the pages created by the BuildReport() function.

When i start to print, my textblock isn't visible on the first printed page as it is supposed to be, but on all the other pages it is visible.

What i did to check if it was a binding problem, was to display all the pages in a TabControl. The result was exactly how i wanted it to be, with my textblocks invisible on the 3 tabs.

It seems the problem is with the PageVisual. I used a converter in my RelativeSource Visibility binding to see what was happening.
Only the RelativeSource visibility bindings of the first page are loaded, the program then prints all my pages and after it is done printing, continues loading the RelativeSource visibility binding for my other pages, giving it the right value, except it's to late.
If i could somehow force it to evaluate the RelativeSource visibility bindings before printing, it should work.

I tried using a update layout on all the grids of my _pageTrees but it didn't change anything.

I hope i was clear, english isn't my first langage and i would allready have a hard time explaining this problem in my mother tongue.

If you have any questions or if someone wants me to upload my project, don't hesitate, i'm desperate to find a solution.

Thank you for your time. 


Viewing all articles
Browse latest Browse all 1083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>