I created a WPF window with custom chrome using Microsoft.Windows.Shell dll. Here is the code for this:
<Style TargetType="Window" x:Key="ChromeLessWindowStyle"> <Setter Property="shell:WindowChrome.WindowChrome"> <Setter.Value> <shell:WindowChrome GlassFrameThickness="0" ResizeBorderThickness="5" CornerRadius="5" CaptionHeight="30"> </shell:WindowChrome> </Setter.Value> </Setter> <Setter Property="WindowStyle" Value="None"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Window}"> <Grid> <Grid Background="#FF595959" > <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Border Grid.Row="0" Height="30" Background="#FF393939"> <DockPanel LastChildFill="False" Margin="0,1,5,0"> <TextBlock DockPanel.Dock="Left" Style="{DynamicResource {x:Static coreKeys:TextBlockKeys.Default}}" FontWeight="Bold" Text="{TemplateBinding Title}" Margin="10,0,0,0" VerticalAlignment="Center"/> <Button DockPanel.Dock="Right" behaviors:WindowCommandBehaviors.IsCloseButton="True" Style="{DynamicResource {x:Static coreKeys:ButtonKeys.Close}}" shell:WindowChrome.IsHitTestVisibleInChrome="True"/> <Button DockPanel.Dock="Right" behaviors:WindowCommandBehaviors.IsMaximizeButton="True" Style="{DynamicResource {x:Static coreKeys:ButtonKeys.Maximize}}" Visibility="{TemplateBinding WindowState,Converter={StaticResource WindowStateToVisibilityConverter},ConverterParameter=MaximizeButton }" shell:WindowChrome.IsHitTestVisibleInChrome="True" /> <Button DockPanel.Dock="Right" behaviors:WindowCommandBehaviors.IsMaximizeButton="True" Style="{DynamicResource {x:Static coreKeys:ButtonKeys.Restore}}" Visibility="{TemplateBinding WindowState,Converter={StaticResource WindowStateToVisibilityConverter}, ConverterParameter=RestoreButton }" shell:WindowChrome.IsHitTestVisibleInChrome="True" /> <Button DockPanel.Dock="Right" behaviors:WindowCommandBehaviors.IsMinimizeButton="True" Style="{DynamicResource {x:Static coreKeys:ButtonKeys.Minimize}}" shell:WindowChrome.IsHitTestVisibleInChrome="True"/> </DockPanel> </Border> <ContentPresenter Grid.Row="1" Content="{TemplateBinding Content}"/> </Grid> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style>
This works in normal scenarios, and I could not detect the problem until I had a requirement to use a window using C # code. I have a messaging service that:
- Creates a modal window.
- Populates its content with a WPF user control.
- Sets the window data context to the corresponding ViewModel.
- Shows a window
Here is the code for this:
var userControl = viewRegistry.GetViewByKey(viewKey_); // Get the UserControl. var modalWindow = new ModalCustomMessageDialog { // Set the content of the window as the user control DataContext = viewModel_, // Set the data context of the window as the ViewModel Owner = Util.AppMainWindow, // Set the owner of the modal window to the app window. WindowStartupLocation = WindowStartupLocation.CenterOwner, //Title = viewModel.TitleText ?? "", ShowInTaskbar = false, Content = userControl, SizeToContent = SizeToContent.WidthAndHeight }; if (showAsToolWindow_) { modalWindow.ResizeMode = ResizeMode.NoResize; modalWindow.WindowStyle = WindowStyle.ToolWindow; } modalWindow.Loaded += modalWindow_Loaded; modalWindow.Closed += CleanModalWindow; modalWindow.Show();
Pay attention to the line
SizeToContent = SizeToContent.WidthAndHeight
This will take care to resize the window to fit the width and height of the user control. Thus, the modal window has a thick black outline on the right and bottom of the window. For instance:

The window should look like (and after resizing):

It is worth noting a few comments:
This black outline disappears as soon as the window is resized.
This outline is not displayed if SizeToContent is set to SizeToContent.Height or SizeToContent.Width. But then it resets either the width or the height of the modal window, respectively.
I thought that there might be a problem with redrawing the window. So I tried the following code to redraw the window:
private const int WmPaint = 0x000F; [DllImport("User32.dll")] public static extern Int64 SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); ......................
It does not affect.
This problem does not appear if I have a fixed Height and Width property specified by User Control that fills the window. However, I cannot do this always.
A messaging service exists with age, and this ghost scheme has appeared recently after a user-defined change in chrome.
Has anyone encountered a similar situation? Any help would be appreciated.