Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF window stretching incorrectly/weird behavior
    text
    copied!<p>I've had a weird behavior in WPF for awhile now, and I haven't been able to trace down where the problem is. In a nutshell, when I resize the window from the bottom or right, everything works as expected. But if I happen to grab it from the top or left, it stretches the window bu not the window contents. I've tried playing around wirh <code>HorizontalContentAlignment</code>, <code>HorizontalAlignment</code>, <code>VerticalContentAlignment</code>, &amp; <code>VerticalAlignment</code> to no avail. Anybody have any ideas where the issue lies?</p> <p><strong>Resize from Left:</strong> <img src="https://i.stack.imgur.com/3gAb4.png" width="200"></p> <p><strong>Resize from Top:</strong> <img src="https://i.stack.imgur.com/1ZPnX.png" width="200"></p> <p><strong>Resize from Right/Bottom:</strong> <img src="https://i.stack.imgur.com/T5tf5.png" width="200"></p> <p>Here's the XAML I'm using, with the inner controls removed for brevity:</p> <p><strong>Window XAML settings:</strong></p> <pre><code>&lt;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"&gt; </code></pre> <p><strong>Container XAML Settings:</strong></p> <pre><code>&lt;DockPanel Name="rvraDockPanel" Background="{Binding ElementName=BackColorPicker, Path=CurrentColor}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt; &lt;Menu Height="Auto" DockPanel.Dock="Top"&gt; &lt;Menu.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;DockPanel HorizontalAlignment="Stretch" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/Menu.ItemsPanel&gt; &lt;WrapPanel Name="buttonDock" Grid.Column="0" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Orientation="Horizontal"&gt; &lt;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"&gt; &lt;Grid Width="{Binding ElementName=bottomStatusBar, Path=ActualWidth}" HorizontalAlignment="Center"&gt; &lt;TabControl Name="tabSelection" HorizontalContentAlignment="Center" Background="{Binding ElementName=BackColorPicker, Path=CurrentColor}"&gt; </code></pre> <p><strong>Update:</strong> LocationChanged code as requested</p> <pre><code> private void Window_LocationChanged(object sender, EventArgs e) { if (Properties.Settings.Default.windowSnap == true) { RealignChild(); } } /// &lt;summary&gt; /// Checks position of any SlideOut windows in relation to main /// program window and aligns child window next to main window. /// &lt;/summary&gt; private void RealignChild() { foreach (Window win in App.Current.Windows) { if (!win.IsFocused &amp;&amp; win.Tag.ToString() == "childWindow" &amp;&amp; win.Left &lt; this.Left) { win.Left = this.Left - win.Width; } if (!win.IsFocused &amp;&amp; win.Tag.ToString() == "childWindow" &amp;&amp; win.Left &gt; this.Left) { win.Left = this.Left + this.Width; } win.Top = this.Top; } } </code></pre> <p>Turns out this was the problem, as when I removed the XAML part of it the problem was corrected. I <em>do</em> want to keep this method though, as there's a method that depends upon it to keep <code>ChildWindows</code> of the <code>MainWindow</code> locked to the edge. I would like to continue using this if possible.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload