Open Feutou opened 4 years ago
Hi @Feutou can you provide a sample here on github which shows your issue?
Thank you and happy coding Tim
Hello, Thank you.
I said, messagebox behind windowsFormsHost, but I think that's displayed behind the reportviewer.
Here is the xaml of this Window
<metro:MetroWindow
x:Class="ImpressionCertificats.Windows.PrintSelectorFicheProductionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:ImpressionCertificats.ViewModel"
xmlns:local="clr-namespace:ImpressionCertificats.Windows"
xmlns:ig="http://schemas.infragistics.com/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Platform"
xmlns:Printing="clr-namespace:System.Drawing.Printing;assembly=System.Drawing"
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
mc:Ignorable="d"
d:DesignWidth="673.893"
d:DesignHeight="398.774"
x:Name="PrinterWindow"
ShowInTaskbar="{Binding DisplayInTaskBar}">
<i:Interaction.Triggers>
<i:EventTrigger
EventName="Closing">
<ei:CallMethodAction
TargetObject="{Binding}"
MethodName="WindowsClosing" />
</i:EventTrigger>
</i:Interaction.Triggers>
<metro:MetroWindow.Resources>
<Style
TargetType="{x:Type Button}"
BasedOn="{StaticResource MetroButton}">
<Setter
Property="Width"
Value="70" />
</Style>
</metro:MetroWindow.Resources>
<DockPanel
Margin="5"
LastChildFill="True">
<Grid
Margin="5"
DockPanel.Dock="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="*" />
<ColumnDefinition
Width="2*" />
</Grid.ColumnDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Content="Imprimante :" />
<ComboBox
Grid.Column="1"
Grid.Row="0"
MinWidth="200"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
ItemsSource="{Binding PrinterDevices,Mode=OneTime}"
SelectedItem="{Binding SelectedPrinterDevice,Mode=TwoWay,NotifyOnValidationError=True,ValidatesOnDataErrors=True}"
Height="26" />
</Grid>
<StackPanel
DockPanel.Dock="Bottom"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Grid.Row="2"
Grid.Column="1"
Orientation="Horizontal">
<Button
Content="Ok"
IsDefault="True"
Command="{Binding PrintCommand}"
Margin="5" />
<Button
Content="Annuler"
IsCancel="True"
Command="{Binding CancelCommand}"
IsEnabled="{Binding CanCancel}"
Margin="5" />
<Button
Content="Fermer"
IsCancel="True"
Command="{Binding CloseWindowCommand}"
CommandParameter="{Binding ElementName=PrinterWindow}"
Margin="5" />
</StackPanel>
<DockPanel
Background="red"
Margin="5"
LastChildFill="True">
<StackPanel
DockPanel.Dock="Top"
Orientation="Horizontal">
<Label
Content="Numéro de document :" />
<Label
Content="{Binding NumDocument}" />
</StackPanel>
<WindowsFormsHost
Margin="70"
Background="green">
<rv:ReportViewer
Margin="5,5,5,5"
x:Name="Viewer"
ProcessingMode="Local"
ShowBackButton="False"
ShowFindControls="False"
ShowPageNavigationControls="true"
ShowRefreshButton="False"
ShowPrintButton="False" />
</WindowsFormsHost>
</DockPanel>
</DockPanel>
</metro:MetroWindow>
what I have in the designer
What I have when I display a message
Hi @Feutou this seems to be impossible as far as I can see. It seems to be a limitation which comes from WPF itself: https://stackoverflow.com/questions/9920480/windowsformshost-is-always-the-most-top-from-wpf-element
Please leave this issue open anyway, maybe someone else has a workaround for this.
Fluent.Ribbon had the same issue when showing the Backstage (which is shown in an adorner).
To overcome such issues every HwndHost
(which WindowsFormsHost
inherits) in the same window gets collapsed when showing the backstage.
Maybe MahApps.Metro could do the same?
The code for that can be found at https://github.com/fluentribbon/Fluent.Ribbon/blob/develop/Fluent.Ribbon/Controls/Backstage.cs#L703
Hello,
On my MetroWindow, I have a dockpanel with lastchildFill = true and the lastChild is a WindowsFormsHost containing a ReportViewer.
When an exception occurs, I display the message by calling the extension method of MetroWindow ShowMessageAsync.
But in this case, the dialog message is displayed behind the windowsFormsHost.
Did I do something wrong? Do you reproduce this behaviour? I suppose that it exists a trick to avoid that?