I have searched far and wide for an answer on this and have come up short. I am using Universal Windows 10 (UWP) and C# in Visual Studio 2015 to build a basic text editor to mirror the functionality of Notepad.exe as practice and I'm running into an annoying display problem/quirk.
I have a Grid with 2 rows. The top row is a horizontal StackPanel
with buttons and the bottom is a RichEditBox
. Everything displays fine.. except when the RichEditBox
has keyboard focus (which I pretty much make sure is always) and I resize the window vertically, the RichEditBox
(and its green border) resizes differently than its Grid container. When I pull the window down to resize, the border of the RichEditBox
"detaches" on the top and bottom and quickly slides back up (and down) to fill the grid. In the process the text jitters around while this animation is taking place. Note: this does NOT happen when I resize horizontally. (image link below it won't let me embed the pic)
It's not the end of the world but it looks unprofessional and there must be a way to anchor the RichEditBox
vertically so it always fills the grid row completely and doesn't pull apart from its container when I resize. I tried all of the properties on the Grid.Row
, the RichEditBox
and its built in ScrollViewer
that I thought could possibly have anything to do with this and no luck. Using the VerticalAlignment = Top
causes the RichEditBox
to no longer fill the grid row vertically (unless I fill it with text of course). I also put the RichEditBox
inside of a ScrollViewer
instead of using its built in ScrollViewer
and it did the same behavior.
Here is my XAML:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Height="Auto" Grid.Row="0" Background="Azure" AllowFocusOnInteraction="False">
<Button x:Name="FileButton" Content="File" Click="MenuButtonClicked" Padding="3,1" Background="Azure">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem Text="New" Click="NewClicked" />
<MenuFlyoutItem Text="Open..." Click="OpenClicked" />
<MenuFlyoutItem Text="Save" Click="SaveClicked" />
<MenuFlyoutItem Text="Save As..." Click="SaveAsClicked" />
<MenuFlyoutItem Text="Close" Click="CloseClicked" />
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="Exit" Click="ExitClicked" />
</MenuFlyout>
</Button.Flyout>
</Button>
<Button x:Name="EditButton" Content="Edit" Click="MenuButtonClicked" Padding="3,1" Background="Azure">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem Text="Undo" Click="UndoClicked" />
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="Cut" Click="CutClicked" />
<MenuFlyoutItem Text="Copy" Click="CopyClicked" />
<MenuFlyoutItem Text="Paste" Click="PasteClicked" />
<MenuFlyoutItem Text="Clear" Click="ClearClicked" />
<MenuFlyoutSeparator/>
<MenuFlyoutItem Text="Date/Time" Click="DateTimeClicked" />
<MenuFlyoutItem Text="Select All" Click="SelectAllClicked" />
</MenuFlyout>
</Button.Flyout>
</Button>
<Button x:Name="FormatButton" Content="Format" Click="MenuButtonClicked" Padding="3,1" Background="Azure">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<ToggleMenuFlyoutItem Text="Word Warp" Click="WordWrapToggled" IsChecked="True"/>
</MenuFlyout>
</Button.Flyout>
</Button>
<Button x:Name="HelpButton" Content="Help" Click="MenuButtonClicked" Padding="3,1" Background="Azure">
<Button.Flyout>
<MenuFlyout Placement="Bottom">
<MenuFlyoutItem Text="About" Click="AboutClicked" />
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
<RichEditBox x:Name="MainTextBox"
FontFamily="Consolas"
FontSize="14"
Grid.Row="1"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
IsSpellCheckEnabled="False"
BorderThickness="1"
TabIndex="0"
ScrollViewer.IsVerticalRailEnabled="True"
ScrollViewer.VerticalScrollMode="Auto"
ScrollViewer.IsHorizontalRailEnabled="True"
ScrollViewer.HorizontalScrollMode="Auto"
KeyDown="TabKeyDown"
Paste="ContentPasted" />
</Grid>
Does anyone know how to make this behave the way I want it to?
I'm grateful for any help that anyone can give.