SEBWIN-106: Fixed placement of browser menu.

This commit is contained in:
dbuechel 2019-03-20 11:39:15 +01:00
parent 5ad8a8a2fb
commit ebdd5b1e03
2 changed files with 27 additions and 17 deletions

View file

@ -20,7 +20,7 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="LightGray" BorderThickness="0,0,0,1" Margin="5,0"> <Border x:Name="Toolbar" Grid.Row="0" BorderBrush="LightGray" BorderThickness="0,0,0,1" Margin="5,0">
<Grid> <Grid>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
@ -37,8 +37,8 @@
<fa:ImageAwesome x:Name="LoadingIcon" Foreground="Gray" HorizontalAlignment="Right" Icon="Spinner" Margin="5,3" SpinDuration="1.5" Visibility="Collapsed" /> <fa:ImageAwesome x:Name="LoadingIcon" Foreground="Gray" HorizontalAlignment="Right" Icon="Spinner" Margin="5,3" SpinDuration="1.5" Visibility="Collapsed" />
</Grid> </Grid>
<Button Grid.Column="4" x:Name="MenuButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" /> <Button Grid.Column="4" x:Name="MenuButton" Height="30" HorizontalAlignment="Center" Margin="5" Template="{StaticResource BrowserButton}" VerticalAlignment="Center" />
<Popup x:Name="MenuPopup" IsOpen="False" Placement="Bottom" PlacementTarget="{Binding ElementName=MenuButton}" HorizontalOffset="-215" VerticalOffset="4"> <Popup x:Name="MenuPopup" IsOpen="False" AllowsTransparency="True" PopupAnimation="Slide" Placement="Custom" PlacementTarget="{Binding ElementName=BrowserControlHost}">
<Border Background="{StaticResource BackgroundBrush}" BorderBrush="LightGray" BorderThickness="0.75,0,0.75,0.75" Width="250"> <Border Background="{StaticResource BackgroundBrush}" BorderBrush="LightGray" BorderThickness="1,0,1,1" Width="250">
<StackPanel Orientation="Vertical"> <StackPanel Orientation="Vertical">
<Grid Height="40"> <Grid Height="40">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

View file

@ -10,6 +10,7 @@ using System;
using System.ComponentModel; using System.ComponentModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
@ -121,20 +122,6 @@ namespace SafeExamBrowser.UserInterface.Desktop
Dispatcher.Invoke(() => Title = title); Dispatcher.Invoke(() => Title = title);
} }
private void InitializeBrowserWindow(IBrowserControl browserControl)
{
if (browserControl is System.Windows.Forms.Control control)
{
BrowserControlHost.Child = control;
}
RegisterEvents();
InitializeBounds();
ApplySettings();
LoadIcons();
LoadText();
}
private void BrowserWindow_Closing(object sender, CancelEventArgs e) private void BrowserWindow_Closing(object sender, CancelEventArgs e)
{ {
if (isMainWindow) if (isMainWindow)
@ -155,6 +142,14 @@ namespace SafeExamBrowser.UserInterface.Desktop
} }
} }
private CustomPopupPlacement[] MenuPopup_PlacementCallback(Size popupSize, Size targetSize, Point offset)
{
return new[]
{
new CustomPopupPlacement(new Point(targetSize.Width - Toolbar.Margin.Right - popupSize.Width, -2), PopupPrimaryAxis.None)
};
}
private void SystemParameters_StaticPropertyChanged(object sender, PropertyChangedEventArgs e) private void SystemParameters_StaticPropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == nameof(SystemParameters.WorkArea)) if (e.PropertyName == nameof(SystemParameters.WorkArea))
@ -180,6 +175,20 @@ namespace SafeExamBrowser.UserInterface.Desktop
} }
} }
private void InitializeBrowserWindow(IBrowserControl browserControl)
{
if (browserControl is System.Windows.Forms.Control control)
{
BrowserControlHost.Child = control;
}
RegisterEvents();
InitializeBounds();
ApplySettings();
LoadIcons();
LoadText();
}
private void RegisterEvents() private void RegisterEvents()
{ {
var originalBrush = MenuButton.Background; var originalBrush = MenuButton.Background;
@ -189,6 +198,7 @@ namespace SafeExamBrowser.UserInterface.Desktop
ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke(); ForwardButton.Click += (o, args) => ForwardNavigationRequested?.Invoke();
MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen; MenuButton.Click += (o, args) => MenuPopup.IsOpen = !MenuPopup.IsOpen;
MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver)); MenuButton.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = MenuPopup.IsMouseOver));
MenuPopup.CustomPopupPlacementCallback = new CustomPopupPlacementCallback(MenuPopup_PlacementCallback);
MenuPopup.Closed += (o, args) => MenuButton.Background = originalBrush; MenuPopup.Closed += (o, args) => MenuButton.Background = originalBrush;
MenuPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = IsMouseOver)); MenuPopup.MouseLeave += (o, args) => Task.Delay(250).ContinueWith(_ => Dispatcher.Invoke(() => MenuPopup.IsOpen = IsMouseOver));
MenuPopup.Opened += (o, args) => MenuButton.Background = Brushes.LightGray; MenuPopup.Opened += (o, args) => MenuButton.Background = Brushes.LightGray;