4

カスタム クロムを使用して WPF ウィンドウを作成しているので、独自のクロムResizeMode="NoResize"WindowStyle="None"実装するように設定しました。ただし、ボーダレス ウィンドウを最大化すると、画面全体が使用されるという問題があります。

問題の一部を修正する次のトリックを見つけました: http://chiafong6799.wordpress.com/2009/02/05/maximizing-a-borderlessno-caption-window/

これにより、ウィンドウのサイズがうまく抑制され、タスクバーが覆われるのを防ぐことができます。ただし、ユーザーがタスクバーを左または上に配置している場合、ウィンドウの位置が 0,0 であるため、これは機能しません。

使用可能な領域をより正確に取得する方法、またはユーザーのタスクバーの位置を照会して、それに応じて最大化されたウィンドウを配置できる方法はありますか?

4

2 に答える 2

5

私はちょっと遊んでみましたが、ボーダレスフォームで設定するWindows LeftTopプロパティとプロパティの設定が無視されるようです。WindowState.Maximized

1 つの回避策は、関数を無視して独自の/関数WindowStateを作成することです。MaximizeRestore

大まかな例。

public partial class MainWindow : Window
{
    private Rect _restoreLocation;

    public MainWindow()
    {
        InitializeComponent();
    }

    private void MaximizeWindow()
    {
        _restoreLocation = new Rect { Width = Width, Height = Height, X = Left, Y = Top };
        System.Windows.Forms.Screen currentScreen;
        currentScreen = System.Windows.Forms.Screen.FromPoint(System.Windows.Forms.Cursor.Position);
        Height = currentScreen.WorkingArea.Height;
        Width = currentScreen.WorkingArea.Width;
        Left = currentScreen.WorkingArea.X;
        Top = currentScreen.WorkingArea.Y;
    }

    private void Restore()
    {
        Height = _restoreLocation.Height;
        Width = _restoreLocation.Width;
        Left = _restoreLocation.X;
        Top = _restoreLocation.Y;
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        MaximizeWindow();
    }

    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
        Restore();
    }

    protected override void OnMouseMove(MouseEventArgs e)
    {
        if (e.LeftButton == MouseButtonState.Pressed)
        {
            DragMove();
        }
        base.OnMouseMove(e);
    }
}

Xaml:

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="74.608" Width="171.708" ResizeMode="NoResize" WindowStyle="None">
    <Grid>
        <Button Content="Max" HorizontalAlignment="Left" Margin="0,29,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
        <Button Content="Restore" HorizontalAlignment="Left" Margin="80,29,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2"/>
    </Grid>
</Window>

明らかに、このコードをクリーンアップする必要がありますが、 が配置されている場所ならどこでも動作するように見えます。ただし、ユーザーのフォント DPI が 100% より大きい場合は、正しいをTaskbar取得するためにいくつかのロジックを追加する必要がある場合があります。LeftTop

于 2013-02-10T22:45:45.003 に答える