Good day
I tried adapting the template example to try and add two strings, one left and one right of a logo
<DataTemplate x:Key="PagePresenterHeaderTemplate"> <Grid Margin="5"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="12"/> </Grid.RowDefinitions> <Image Source="/Pathname" Height="50" Width="50" HorizontalAlignment="Center"/> <Label Height="50" Content="{Binding Path=left}" Padding="10,0" VerticalContentAlignment="Center"/> <Label Height="50" Content="{Binding Path=right}" Padding="10,0" VerticalContentAlignment="Center" HorizontalAlignment="Right" HorizontalContentAlignment="Right"/> <Border BorderThickness="1" BorderBrush="Black" Height="2" Margin="20,0,20,0" VerticalAlignment="Bottom" Grid.ColumnSpan="2" Grid.Row="1"/> </Grid> </DataTemplate>
and then created a class
public class Headerstrings { public string left; public string right; }
and tried to bind using
// apply header template reportObj.PageHeaderTemplate = this.Resources["PagePresenterHeaderTemplate"] as DataTemplate; Headerstrings headerstrings = new Headerstrings(); headerstrings.left = "left"; headerstrings.right = "right"; reportObj.PageHeader = headerstrings;
What am I doing wrong? Is that not how it should work?
have you tried to define the data context of the dataTemplate has your headerstrings?like:
var pageHeader = new PagePresenterHeaderTemplate { DataContext = headerstrings };
and then
reportObj.PageHeader = pageHeader