0

しばらくの間、WPF で奇妙な動作が発生しましたが、問題がどこにあるのかを突き止めることができませんでした。一言で言えば、ウィンドウのサイズを下または右から変更すると、すべてが期待どおりに機能します。しかし、たまたま上または左からそれをつかむと、ウィンドウの内容ではなくウィンドウが引き伸ばされます。HorizontalContentAlignmentHorizontalAlignmentVerticalContentAlignment、 &で遊んでみましたが、役に立ちVerticalAlignmentませんでした。問題がどこにあるのか誰にも考えがありますか?

左からサイズ変更:

上からサイズ変更:

右/下からサイズ変更:

簡潔にするために内部コントロールを削除した、使用している XAML を次に示します。

ウィンドウの XAML 設定:

<Window x:Class="Agent_Template.MainWindow"
    Width="{Binding Source={x:Static main:Properties.Settings.Default}, Path=Width, Mode=TwoWay}" 
    FontFamily="{Binding Source={x:Static main:Properties.Settings.Default}, Path=currentFont, Mode=TwoWay}"
    FontSize="{Binding Source={x:Static main:Properties.Settings.Default}, Path=currentFontSize, Mode=TwoWay}"
    Foreground="{Binding Source={x:Static main:Properties.Settings.Default}, Path=foregroundColor, Mode=TwoWay}"
    LocationChanged="Window_LocationChanged" Tag="parentWindow"
    Top="{Binding Source={x:Static main:Properties.Settings.Default}, Path=Top, Mode=TwoWay}"
    Topmost="False">

コンテナーの XAML 設定:

<DockPanel Name="rvraDockPanel" Background="{Binding ElementName=BackColorPicker, Path=CurrentColor}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
    <Menu Height="Auto" DockPanel.Dock="Top">
<Menu.ItemsPanel>
            <ItemsPanelTemplate>
                <DockPanel HorizontalAlignment="Stretch" />
            </ItemsPanelTemplate>
        </Menu.ItemsPanel>
<WrapPanel Name="buttonDock" Grid.Column="0" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Orientation="Horizontal">
<StatusBar Name="bottomStatusBar" Height="28" MinWidth="{Binding ElementName=buttonPanel, Path=ActualWidth}" Background="{Binding ElementName=clearButton, Path=Background}" BorderBrush="White" DockPanel.Dock="Bottom" Focusable="False" FontFamily="{Binding ElementName=fontSelector, Path=SelectedValue}" FontWeight="Bold" Foreground="Blue">
        <Grid Width="{Binding ElementName=bottomStatusBar, Path=ActualWidth}" HorizontalAlignment="Center">
<TabControl Name="tabSelection" HorizontalContentAlignment="Center" Background="{Binding ElementName=BackColorPicker, Path=CurrentColor}">

更新:要求に応じて LocationChanged コード

    private void Window_LocationChanged(object sender, EventArgs e)
    {
        if (Properties.Settings.Default.windowSnap == true)
        {
            RealignChild();
        }
    }

    /// <summary>
    /// Checks position of any SlideOut windows in relation to main
    /// program window and aligns child window next to main window.
    /// </summary>
    private void RealignChild()
    {
        foreach (Window win in App.Current.Windows)
        {
            if (!win.IsFocused && win.Tag.ToString() == "childWindow" && win.Left < this.Left)
            {
                win.Left = this.Left - win.Width;                    
            }

            if (!win.IsFocused && win.Tag.ToString() == "childWindow" && win.Left > this.Left)
            {
                win.Left = this.Left + this.Width;                   
            }

            win.Top = this.Top;
        }
    }

XAML の部分を削除したときに問題が修正されたため、これが問題であることが判明しました。ただし、エッジにロックされた状態を維持するためにそれに依存する方法があるため、この方法を維持たいと考えています。できればこのまま使い続けたいです。ChildWindowsMainWindow

4

1 に答える 1

0

カスタム Window Resize メソッドを使用していますか? 私自身の経験から、デフォルトの Windows ResizeMethod (のようにWindowStyle = AnythingButNone) を使用しない限り、どこからでもバーのサイズを変更すると、Bottom/Right で問題が発生することがわかります (Microsoft のせいです。Google で少し調べれば確認できます)。

デフォルトの Windows ResizeMethod を使用していない場合は、コードを投稿していただけますか? それ以外の場合は、問題が Windows プロパティ内にあるか、ウィンドウ全体を含む基本要素の 1 つにあると想定する必要があります。

于 2012-12-16T10:23:33.967 に答える