The MindFusion Forums
MindFusion.Reporting >> WPF >> Binding CustomReportItem to Data
https://mindfusion.eu/Forum/YaBB.pl?num=1327090325

Message started by seifedias on Jan 20th, 2012 at 8:12pm

Title: Binding CustomReportItem to Data
Post by seifedias on Jan 20th, 2012 at 8:12pm
Hi,

I just downloaded the ReportingTrial to take a closer look. I added a CustomReportItem to arrange some Data:


Code (]
<r:CustomReportItem Name="Kopf" Location="20,10" Width="300" Height="100">
           <r:CustomReportItem.Template>
               <DataTemplate>
                   <Grid>
                       <Grid.ColumnDefinitions>
                           <ColumnDefinition></ColumnDefinition>
                           <ColumnDefinition></ColumnDefinition>
                           <ColumnDefinition></ColumnDefinition>
                       </Grid.ColumnDefinitions>
                       <TextBlock Text="[Name):

" />
                       <TextBlock Grid.Column="1" Text="[Vorname]" />
                       <TextBlock Grid.Column="2" Text="[Alter]" />
                   </Grid>
               </DataTemplate>
           </r:CustomReportItem.Template>
       </r:CustomReportItem>

Now I'm trying to bind the textblocks to a datasource by setting the Datacontext-property of the CustomReportItem to display actual data instead of static text. Unfortunatly it just won't work.

Can anybody tell me how to achieve this? The datasource is a class which exposes the properties "Name", "Vorname" and "Alter".

Thanks for any answers

Title: Re: Binding CustomReportItem to Data
Post by Meppy on Jan 23rd, 2012 at 8:15am
Try the following custom item template:

[code]<r:CustomReportItem Name="Kopf" Location="20,10" Size="300,100" Value="{Binding}">
      <r:CustomReportItem.Template>
            <DataTemplate>
                  <Grid>
                        <Grid.ColumnDefinitions>
                              <ColumnDefinition></ColumnDefinition>
                              <ColumnDefinition></ColumnDefinition>
                              <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{Binding Name}" />
                        <TextBlock Grid.Column="1" Text="{Binding Vorname}" />
                        <TextBlock Grid.Column="2" Text="{Binding Alter}" />
                  </Grid>
            </DataTemplate>
      </r:CustomReportItem.Template>
</r:CustomReportItem>[/code]

The following changes were made:

1. The size of the report items needs to be specified through ReportItem.Size, rather than setting it through the FrameworkElement properties directly.

2. The item's Value is bound to the current DataContext so that the bindings inside the item can be resolved properly.

3. The MindFusion reporting expressions (those surrounded in square brackets) can be used directly only for the MindFusion.Reporting.Wpf.Label.Text and MindFusion.Reporting.Wpf.CustomReportItem.Value properties. You can still use them for any other property through the Expression extension, but it is easier to simply use regular WPF bindings instead. In the above case the TextBlock.Text property values have been changed to regular bindings.

I hope this helps.

Regards,
Meppy

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.