マルチスクリーン対応のマルチウィンドウでアプリケーションを開発しています。私はすべてのウィンドウのために私自身のタイトルバーを作った。デュアルスクリーン用の最大化機能の管理
私のタイトルバー:機能付き
<Grid x:Class="TitleBar"
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"
Style="{DynamicResource TitleStyle}"
MouseLeftButtonDown="gridBar_MouseLeftButtonDown"
x:Name="titleBar">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Column="0" [...]/>
<Button Grid.Column="1" x:Name="bttnClose" [...]/>
<Button Grid.Column="1" x:Name="buttonMinimize" [...]/>
</Grid>
:
private void gridBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (Window.GetWindow(this) != null)
{
if (e.ClickCount == 2) // double click handle
{
if (Window.GetWindow(this).WindowState == WindowState.Normal)
Window.GetWindow(this).WindowState = WindowState.Maximized;
else
Window.GetWindow(this).WindowState = WindowState.Normal;
}
try
{
Window.GetWindow(this).DragMove();
}
catch { }
}
}
すべての私の窓は(最大/最小の高さと幅に等しいです)、メインウィンドウを除いて、かなりの再されていません。ですから、私はフルスクリーンからマルチスクリーン環境を管理したいと思っています。
私は私のMainWindow
クラスでこれを追加しました:
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == WindowState.Maximized)
{
var hwnd = new System.Windows.Interop.WindowInteropHelper(this).EnsureHandle();
var currentMonitor = NativeMethods.MonitorFromWindow(hwnd, NativeMethods.MONITOR_DEFAULTTONEAREST);
var primaryMonitor = NativeMethods.MonitorFromWindow(IntPtr.Zero, NativeMethods.MONITOR_DEFAULTTOPRIMERTY);
var isInPrimary = currentMonitor == primaryMonitor;
// Don't want to hide the taskbar
if (isInPrimary)
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
else
this.MaxHeight = Double.PositiveInfinity;
}
base.OnStateChanged(e);
}
internal static class NativeMethods
{
public const Int32 MONITOR_DEFAULTTOPRIMERTY = 0x00000001;
public const Int32 MONITOR_DEFAULTTONEAREST = 0x00000002;
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr MonitorFromWindow(IntPtr handle, Int32 flags);
}
それはほとんど動作しますが、私はMaxHeight
を設定すると、それは実際のHeight
をリフレッシュしません。私は画面で2倍にして、正しいサイズにしなければならなかった。
あなたは私を助けることができますか?
タスクバーが左または右にある場合、またはセカンダリモニタにも表示されている場合は、 – Phil1970
この場合、動作しません:-(。このコードは非常に基本的なものであり、ちょうど1つのケースを考慮していますが、.NETがアクティブエリアとスクリーンを簡単に管理する機能を備えていない(または、 –