Set your XAML as the following:
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
WindowStartupLocation="Manual"
Title="MainWindow" SizeToContent="Height" ResizeMode="NoResize" Topmost="True"
WindowState="Maximized">
<Grid>
<TextBlock Text="Hi there!" FontSize="36"/>
</Grid>
</Window>
We set SizeToContent = Height
to achieve the height auto effect. WindowState=Maximized
to achieve full width for the window.
Then in the codebehind use the following code to avoid that the user moves the window around:
public partial class MainWindow
{
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
public MainWindow()
{
InitializeComponent();
SourceInitialized += OnSourceInitialized;
Left = 0;
Top = 0;
}
private void OnSourceInitialized(object sender, EventArgs e)
{
var helper = new WindowInteropHelper(this);
var source = HwndSource.FromHwnd(helper.Handle);
source.AddHook(WndProc);
}
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case WM_SYSCOMMAND:
int command = wParam.ToInt32() & 0xfff0;
if (command == SC_MOVE)
{
handled = true;
}
break;
default:
break;
}
return IntPtr.Zero;
}
}
I must say that I took the last part from this answer by @Thomas Levesque.
The result is a nice top docked window with full width