locked
Print elements added in code

    Question

  • Hi,

    I'm using the Print Sample for windws store apps.

    I want to do something similar with elements added in code ( not in the xaml).

    but elements I add in code to the printableArea do not appear on the printed page.

    any idea how to solve this problem?

    thanks.


    Spaarvap

    Sunday, February 09, 2014 2:57 PM

Answers

  • sorry, i figured out what was the issue - the printed page and the displayed page were declared seperatly.

    Spaarvap

    • Marked as answer by spaarvap Monday, February 10, 2014 9:05 AM
    Monday, February 10, 2014 9:05 AM

All replies

  • Hi,

    lt is difficult to detect why you cannot add elements in code. You should share your code in forum or upload your project to skyDrive.

    And if you want to add a control to page without in xaml, you should define a parent container(such as Grid, StackPanel)in the visual tree and make the control added to the parent container children.

    You can see How to add a checkbox

    Step 2: Add a check box in code

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, February 10, 2014 3:46 AM
  • this is the xaml:

    <RichTextBlock Foreground="Black" x:Name="textContent" FontSize="18" Grid.Row="1"  Grid.ColumnSpan="2" OverflowContentTarget="{Binding ElementName=firstLinkedContainer}" 
                           IsTextSelectionEnabled="True" TextAlignment="Left" FontFamily="Segoe UI" VerticalAlignment="Top" HorizontalAlignment="Left">
                <Paragraph>
                    <InlineUIContainer>
                        <ScrollViewer x:Name="svView" HorizontalScrollBarVisibility="Visible"  VerticalScrollBarVisibility="Visible" FlowDirection="RightToLeft" Height="768" >
                            <Grid Name="grid1">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="100"></RowDefinition>
                                    <RowDefinition Height="50"></RowDefinition>
                                    <RowDefinition Height="*"></RowDefinition>
                                </Grid.RowDefinitions>
                                <!--<Image Grid.Row="0" Source="Assets/SmallLogo.png" Width="50" Height="100" ></Image>-->
                                <Canvas Grid.Row="1" x:Name="canvasView" Height="771" Width="1361"  HorizontalAlignment="Center" VerticalAlignment="Center">
                                </Canvas>
                                <Grid Grid.Row="2" x:Name="gridView"  HorizontalAlignment="Center" Height="771" Width="1361" VerticalAlignment="Center" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
                            </Grid>
                        </ScrollViewer>
                    </InlineUIContainer>
                </Paragraph>
            </RichTextBlock>

    when I define the image in xaml it appears on the screen and on the printed page.

    but when I add it in code - 

    Image im = new Image();
    Grid.SetRow(im, 0);
    BitmapImage bmp = new BitmapImage(new Uri("ms-appx:///Assets/SmallLogo.png"));
    im.Source = bmp;
    im.Width=50; 
    im.Height=100;
    grid1.Children.Add(im);

    it appears on the sceen but not on the pinted page .

    (the printed page is loaded after the screen is loaded.)


    Spaarvap

    Monday, February 10, 2014 8:49 AM
  • sorry, i figured out what was the issue - the printed page and the displayed page were declared seperatly.

    Spaarvap

    • Marked as answer by spaarvap Monday, February 10, 2014 9:05 AM
    Monday, February 10, 2014 9:05 AM