Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Stimulsoft Reports.WPF discussion
Post Reply
InnoM
Posts: 4
Joined: Fri Sep 29, 2023 12:41 pm

Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Post by InnoM »

Hi,

I've been experimenting with adding Stimulsoft to our reporting software.
When using the StiWpfViewerControl, I have something similar to:

Code: Select all

<DataTemplate DataType="{x:Type tabs:StimulsoftTab}">
        <stim:StiWpfViewerControl Report="{Binding Report}"/>
</DataTemplate>
In the XAML for the tab control that is used to display reports in window. The class looks like:

Code: Select all

public class StimulsoftTab
{
...
	private StiReport _Report;
        public StiReport Report
        {
            get => _Report;
            set
            {
                _Report = value;
                OnPropertyChanged();
            }
        }
...
}
Simple MVVM wpf stuff. However, it appears that the "Report" DependencyProperty does not bind to anything. I tried with different bindings, using X:Null just to test etc. Nothing seems to affect it except going into "Open" when running the software.

I even confirmed this by stepping through the code in visual studio after decompiling the Stimulsoft assembly and placing a breakpoint at

Code: Select all

Stimulsoft.Report.Viewer.StiWpfViewerControl.OnReportChanged
, which is the method that handles the report dependencyproperty changed event. This event is never hit from WPF XAML binding, only through opening in software or by changing Report in code.

Can anyone help me understand why the Report binding doesn't seem to work? Is there another property I should be using?

Thanks in advance
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Post by Lech Kulikowski »

Hello,

Sorry, maybe we did not exactly understand your problem. Could you explain your issue in more detail?

Also, please send us a sample project for analysis.

Thank you.
InnoM
Posts: 4
Joined: Fri Sep 29, 2023 12:41 pm

Re: Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Post by InnoM »

Hi Lech,

I've attached a sample WPF project. It uses a TabControl with resources to bind datatemplates using the StiWpfViewerControl.

When making this sample, I realised that the Report binding will work when not using the viewer control in a datatemplate.

E.g. if using the TabItem control inside a TabControl the report will bind fine.

When running this, you will notice that the Report property on the StiWpfViewerControl is not set.

Kind Regards
Attachments
WpfApp2.zip
(2.85 KiB) Downloaded 192 times
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Post by Lech Kulikowski »

Hello,

We don't quite understand your example and why it doesn't work.
Binding works on passing the report to the viewer, via Binding. We have a wpf property - DependencyProperty, we can't process the Binding ourselves - the system does it and changing the property doesn't work in your case.

Thank you.
Attachments
photo_2023-10-02_12-34-43.jpg
photo_2023-10-02_12-34-43.jpg (127.39 KiB) Viewed 14440 times
InnoM
Posts: 4
Joined: Fri Sep 29, 2023 12:41 pm

Re: Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Post by InnoM »

Hi Lech,

Sorry I didn't reply sooner.
I've forgotten to add the call to "Load" here, but even with that and call to Render it's the same effect.

I think I raised this to highlight how the Binding dependency property doesn't get updated when the control is hosted in a tabcontrol like the one in my sample.
When using the viewer control in a normal window like you've done it binds fine, but when in a tabcontrol (possibly any items control?) it doesn't bind.

Our use case here is allowing the user to select an array of reports and view them in our application.
I suspect there is some quirk with how the viewer control is set to render when inside an items control like the tabcontrol in WPF.

Kind Regards
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Post by Lech Kulikowski »

Hello,

We need some time to investigate the issue. We will let you know about the result.

Thank you.
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Binding values to "Report" on StiWpfViewerControl doesn't seem to function

Post by Lech Kulikowski »

Hello,

We have not encountered this before.
If, for example, we add another DependencyProperty to the viewer, which is completely the same as Report, but of type String, then bindings to it work and we can't explain it either, because there is no difference.

Code: Select all

        public static readonly DependencyProperty TestProperty = DependencyProperty.Register("Test", typeof(string),
            typeof(StiWpfViewerControl), new FrameworkPropertyMetadata(null,
                FrameworkPropertyMetadataOptions.AffectsMeasure |
                FrameworkPropertyMetadataOptions.AffectsRender,
                new PropertyChangedCallback(OnTestChanged))));
        [Category("Report")]
        public string Test
        {
            get => (string)this.GetValue(TestProperty);
            set => this.SetValue(TestProperty, value);
        }
        private static void OnTestChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var viewer = sender as StiWpfViewerControl;

            var oldReport = e.OldValue as string;
            var value = e.NewValue as string;

            //var report = new StiReport();
            //report.Load(value);
            //report.RenderWithWpf(false);

            //viewer.Report = report;
        }
do this: <wpfViewer:StiWpfViewerControl Report="{Binding Report}" Test="{Binding Name}"/>
{Binding Report} - doesn't work
{Binding Name} - works.

We don't know what is causing this. If you have any ideas, please email us.
The only thing we can suggest right now for this situation is not to use MVVM. Create a new TabItem, add a DependencyProperty Report to it and connect it via TemplateBinding, we don't see any other option at the moment.

Thank you.
Post Reply