问题描述:

I have this window with dynamic content. Increasing the text of the TextBlock increases the height of the window as well.

<Window x:Class="MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="MainWindow"

ResizeMode="NoResize"

SizeToContent="Height"

AllowsTransparency="True"

WindowStyle="None"

Background="MediumPurple"

Topmost="True" MinWidth="478" MinHeight="124"

>

<!--Background="{x:Null}"-->

<Grid Margin="0,0,0,0" Background="SlateGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">

<TextBlock Name="SubTextBlock" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" Margin="0,0,0,32" Foreground="#FFFFFFFF" FontFamily="Arial" FontSize="24" TextWrapping="WrapWithOverflow" FontWeight="SemiBold" TextAlignment="Center" ScrollViewer.VerticalScrollBarVisibility="Hidden">

<TextBlock.Effect>

<DropShadowEffect ShadowDepth="0" Color="Black" Opacity="1" Direction="0" BlurRadius="5" />

</TextBlock.Effect><Run Text="bla bla bla vla dasd gsfg duryktry ytrjhryt ju5635jtyjk tuk tej tu k ti56u46u234 h jreyjry dssfgf dss"/></TextBlock>

<Rectangle Name="Mainrect" Fill="#FFC31A1A" MouseLeftButtonDown="Rectangle_MouseLeftButtonDown" Margin="0,0,0,5" HorizontalAlignment="Center" Width="20" VerticalAlignment="Bottom" Height="20" RenderTransformOrigin="0.6,1.75" ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden">

<Rectangle.ContextMenu>

<ContextMenu>

<MenuItem Header="Select *.SRT file..." Click="MenuItem_Open"/>

<MenuItem Name="resize_mitem" Header="Enable Resizing" Click="Resize_mitem_OnClick"/>

<MenuItem Header="Impostazioni" Click="MenuItem_Settings" IsEnabled="False"/>

<Separator />

<MenuItem Header="Esci" Click="MenuItem_Quit"/>

</ContextMenu>

</Rectangle.ContextMenu>

</Rectangle>

<Grid Name="Playstop" MouseLeftButtonDown="Playstop_OnMouseLeftButtonDown" Margin="10,0,0,5" HorizontalAlignment="Left" Width="20" VerticalAlignment="Bottom" Height="20" ToolTip="Play / Stop">

<Rectangle Fill="#00ff00" />

<TextBlock Name="GlyphPaused" Foreground="Black" FontSize="16" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,-1,1">▶</TextBlock>

<TextBlock Name="GlyphPlaying" Foreground="Black" FontSize="16" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,1" Visibility="Collapsed">❚❚</TextBlock>

</Grid>

<Grid Name="IncreaseLatency" MouseLeftButtonDown="IncreaseLatency_OnMouseLeftButtonDown" Margin="0,0,10,5" HorizontalAlignment="Right" Width="20" VerticalAlignment="Bottom" Height="20" ToolTip="Play / Stop">

<Rectangle Fill="#0000ff" />

<TextBlock Foreground="White" FontSize="18" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="1,-3,1,-1">➕</TextBlock>

</Grid>

<Grid Name="LowerLatency" MouseLeftButtonDown="Playstop_OnMouseLeftButtonDown" Margin="0,0,40,5" HorizontalAlignment="Right" Width="20" VerticalAlignment="Bottom" Height="20" ToolTip="Play / Stop">

<Rectangle Fill="#0000ff" />

<TextBlock Foreground="White" FontSize="18" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="1,-3,1,-1">➖</TextBlock>

</Grid>

</Grid>

The problem

My problem here is that when window size is increased my controls slide down. I'd like to have fixed controls and the new textblock space sliding up.

I am looking for a XAML solution, if possible. Else anything will be fine.


Update

I came up with this, but it flickers.

Private Sub MainWindow_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles Me.SizeChanged

Dim ps = e.PreviousSize

Dim ns = e.NewSize

Dim delta As Integer = ns.Height - ps.Height

Me.Top -= delta

End Sub

相关阅读:
Top