しばらくの間、WPF で奇妙な動作が発生しましたが、問題がどこにあるのかを突き止めることができませんでした。一言で言えば、ウィンドウのサイズを下または右から変更すると、すべてが期待どおりに機能します。しかし、たまたま上または左からそれをつかむと、ウィンドウの内容ではなくウィンドウが引き伸ばされます。HorizontalContentAlignment
、HorizontalAlignment
、VerticalContentAlignment
、 &で遊んでみましたが、役に立ち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 の部分を削除したときに問題が修正されたため、これが問題であることが判明しました。ただし、エッジにロックされた状態を維持するためにそれに依存する方法があるため、この方法を維持したいと考えています。できればこのまま使い続けたいです。ChildWindows
MainWindow