Search code examples
c#wpfxamlrdlcwindowsformshost

WindowsFormHost not working for WPF user control


I want to display a report through reportviewer using windowsformhost from a WPF usercontrol, i found no errors & warning when debugging , but when i run program windowsformhost seems hidden. same code works fine (windowsformhost is visible ) when i change usercontrol to a window

Any ideas ? whats wrong here?

<UserControl x:Class="myProj.UserControls.Reportrs.ucSalesReport"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            mc:Ignorable="d" 
          xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
         xmlns:RV="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" 

         d:DesignHeight="768" FontFamily="Open Sans"
         d:DesignWidth="1024" Background="#e3e7e8" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="7"></ColumnDefinition>
        <ColumnDefinition Width="2*"></ColumnDefinition>
        <ColumnDefinition Width="7"></ColumnDefinition>
        <ColumnDefinition Width="2*"></ColumnDefinition>
        <ColumnDefinition Width="7"></ColumnDefinition>
        <ColumnDefinition Width="2*"></ColumnDefinition>
        <ColumnDefinition Width="7"></ColumnDefinition>
        <ColumnDefinition Width="2*"></ColumnDefinition>
        <ColumnDefinition Width="7"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="30"></RowDefinition>
        <RowDefinition Height="50"></RowDefinition>
        <RowDefinition Height="7"></RowDefinition>
        <RowDefinition Height="*"></RowDefinition>
        <RowDefinition Height="7"></RowDefinition>
    </Grid.RowDefinitions>
    <Label Grid.Column="1" Content="From Date" VerticalAlignment="Center"></Label>
    <Label Grid.Column="3" Content="To Date" VerticalAlignment="Center"></Label>

    <DatePicker Style="{StaticResource DatePickerStyleFromNew}" Name="dpFrom" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="30"></DatePicker>
    <DatePicker Style="{StaticResource DatePickerStyleFromNew}" Name="dpTo" Grid.Column="3" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="30" Width="auto"></DatePicker>

    <Button Name="btnReport" Click="btnReport_Click" Margin="5" Style="{StaticResource styleNormalYellowButton}" Content="REPORT" Grid.Row="1" Grid.Column="7"></Button>
    <WindowsFormsHost  x:Name="winFormHost"  Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="7" >
        <WindowsFormsHost.Child>
            <RV:ReportViewer x:Name="SalesReportViewer" BorderStyle="FixedSingle" ProcessingMode="Local"></RV:ReportViewer>
        </WindowsFormsHost.Child>
    </WindowsFormsHost>
</Grid>


Solution

  • Setting Up AllowsTransparency="False" For Window Is Fixed This Issue.