Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
570
DataTemplate for headings and multiple values
posted

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?

Parents
No Data
Reply
  • 25
    Suggested Answer
    posted

    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

Children
No Data