We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DataTemplate Binding Data Print?

Thread ID:

Created:

Updated:

Platform:

Replies:

121580 Jan 5,2016 07:03 AM UTC Jan 6,2016 01:02 PM UTC WPF 1
loading
Tags: SfDataGrid
jenny park
Asked On January 5, 2016 07:03 AM UTC

Hello, Sir

I would like to DataTemplate Binding print 
I had coded as follows
But, The binding data is not visible to the DataTemplate  
SfDataGrid.PrintSettings.PrintPageHeaderTemplate = Resources["PrintHeader"] as DataTemplate;
How do could be done with binding print the contents of the DataTemplate to print? 

xaml
<DataTemplate x:Key="PrintHeader"  >
            <Border BorderThickness="1">
                <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="50"></RowDefinition>
                    <RowDefinition Height="25"></RowDefinition>
                    <RowDefinition Height="25"></RowDefinition>
                    <RowDefinition Height="25"></RowDefinition>
                    <RowDefinition Height="50"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>
                
                <TextBlock HorizontalAlignment="Center" FontSize="20" Text="TEST PRINT " Grid.ColumnSpan="4"/>
                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="1" FontSize="12" Text="NAME:" ></TextBlock>
                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="2" FontSize="12" Text="COMPANY:"></TextBlock>
                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="3" FontSize="12" Text="START TIME:"></TextBlock>
                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="4" FontSize="12" Text="END TIME:"></TextBlock>
                    <TextBlock Grid.Row="1"  Grid.Column="1" FontSize="12" HorizontalAlignment="Left" Text="{Binding Path= _Name, Mode=TwoWay}"/>
                    <TextBlock Grid.Row="2"  Grid.Column="1" FontSize="12" HorizontalAlignment="Left" Text="{Binding _CompanyName}" />
                    <TextBlock Grid.Row="3"  Grid.Column="1" FontSize="12" HorizontalAlignment="Left" Text="{Binding _StartTime}" />
                    <TextBlock Grid.Row="3"  Grid.Column="1" FontSize="12" HorizontalAlignment="Left" Text="{Binding _EndTime}" />
                </Grid>
            </Border>
        </DataTemplate>


       <ListBox Grid.Row="2" Width="400" Margin="10"  ItemsSource="{Binding PrintItemList}" ItemTemplate="{StaticResource PrintHeader}"   HorizontalContentAlignment="Stretch" Visibility="Collapsed" x:Name="printListView"/>


xaml.cs


private void PrintButton_Click(object sender, RoutedEventArgs e)
        {

            for (int i = 0; i < 1; i++)
            {
                PrintItemList.Add(new GradingRunPrintDetailItem() { _MemoryName = MemoryName.Text, _Company = "Company", _StartTime = TimeStart.Text, _EndTime = TimeEnd.Text, _FarmName = farmNameValue, _TotalCount = TotalSumWeight.Text, _TotalWeight = TotalSumCount.Text, _TotalAvgWeight = "0" });
            }

            if (SfDataGrid== null) return;
            string PrintMemoryName = MemoryName.Text;
            string FarmNameVal = FarmNameValue;
            string StartTimeVal = TimeStart.Text;
            string EndTimeVal = TimeEnd.Text;

            SfDataGrid.PrintSettings.AllowRepeatHeaders = false;
            SfDataGrid.PrintSettings.PrintPageHeaderHeight = 170;
            //SfDataGrid.PrintSettings.PrintManagerBase.PrintPageOrientation = PrintOrientation.Landscape;

            SfDataGrid.PrintSettings.PrintPageHeaderTemplate = Resources["PrintHeader"] as DataTemplate;
            SfDataGrid.ShowPrintPreview();
        } 


   SfDataGrid.PrintSettings.PrintPageHeaderTemplate = Resources["PrintHeader"] as DataTemplate;




Jai Ganesh S [Syncfusion]
Replied On January 6, 2016 01:02 PM UTC

Hi Jenny,

We cannot understand your requirement clearly. We suspect that your reported problem is , the binding is not worked for some properties that is declared inside the DataTemplate . If this is your requirement then you can setting the DataContext like below code example,

Code Example:

<Window.Resources>

        <local:ViewModel x:Key="viewmodel"/>

        <DataTemplate x:Key="PrintHeader"  >

           

            <Border BorderThickness="1">

                <Grid DataContext="{StaticResource viewmodel}">

                    <Grid.RowDefinitions>

                        <RowDefinition Height="50"></RowDefinition>

                        <RowDefinition Height="25"></RowDefinition>

                        <RowDefinition Height="25"></RowDefinition>

                        <RowDefinition Height="25"></RowDefinition>

                        <RowDefinition Height="50"></RowDefinition>

                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>

                        <ColumnDefinition></ColumnDefinition>

                        <ColumnDefinition></ColumnDefinition>

                    </Grid.ColumnDefinitions>


                    <TextBlock HorizontalAlignment="Center" FontSize="20" Text="TEST PRINT " Grid.ColumnSpan="4"/>

                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="1" FontSize="12" Text="NAME:" ></TextBlock>

                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="2" FontSize="12" Text="COMPANY:"></TextBlock>

                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="3" FontSize="12" Text="START TIME:"></TextBlock>

                    <TextBlock HorizontalAlignment="Right" Width="120" Grid.Row="4" FontSize="12" Text="END TIME:"></TextBlock>

                    <TextBlock Grid.Row="1"  Grid.Column="1" FontSize="12" HorizontalAlignment="Left" Text="{Binding TemplateName}"/>

                   

                </Grid>

            </Border>

        </DataTemplate>


    </Window.Resources>


In other way, you can give a source when  binding data like below code example,


<TextBlock Grid.Row="1"  Grid.Column="1" FontSize="12" HorizontalAlignment="Left" Text="{Binding TemplateName,Source={StaticResource viewmodel}}"/>


If the above one is not your requirement, could you please share the more details for whether you want to perform the print for ListBox data or SfDataGrid? This would be more helpful for us to analyze further.

Regards,
Jai Ganesh S

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;