Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent visual for Wpf grid showing black line on right depending on size #9816

Open
ejohnson-dotnet opened this issue Sep 19, 2024 · 1 comment

Comments

@ejohnson-dotnet
Copy link

Description

I have a simple WPF app with a grid showing textblocks and textboxes.

If the textblock is a certain length, the window shows a black vertical bar on the right.
Adding one character to the textblock eliminates the black bar.

Here is the Xaml code for the window. If you add one character or remove one character from the textblock, the line on the right goes away.

I have screen shots of the window below.

<Window x:Class="MyApp.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"
		xmlns:local="clr-namespace:MyApp"
		mc:Ignorable="d"
		Title="Title" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" >
	<Grid  >
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition />
		</Grid.ColumnDefinitions>

		<TextBlock Grid.Row="0" Margin="2" Text="123456789 123456789 1234567" />
		<TextBlock Grid.Row="1" Margin="2" Text="123456789 123456789" />
		<TextBlock Grid.Row="2" Margin="2" Text="123456789 123456789" />
		<TextBlock Grid.Row="3" Margin="2" Text="123456789 123456789" />
		<TextBlock Grid.Row="4" Margin="2" Text="123456789 123456789" />

		<TextBox Grid.Row="0" Grid.Column="1" Margin="2" MaxLength="10" Width="90" />
	</Grid>
</Window>

This window shows a black bar on the right
Screenshot 2024-09-19 161056

This window does not show the bar. The only difference is the text length.
Screenshot 2024-09-19 161138

Reproduction Steps

Use this code in a WPF Xaml window:

<Window x:Class="MyApp.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"
		xmlns:local="clr-namespace:MyApp"
		mc:Ignorable="d"
		Title="Title" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" >
	<Grid  >
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="Auto"/>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition />
		</Grid.ColumnDefinitions>

		<TextBlock Grid.Row="0" Margin="2" Text="123456789 123456789 1234567" />
		<TextBlock Grid.Row="1" Margin="2" Text="123456789 123456789" />
		<TextBlock Grid.Row="2" Margin="2" Text="123456789 123456789" />
		<TextBlock Grid.Row="3" Margin="2" Text="123456789 123456789" />
		<TextBlock Grid.Row="4" Margin="2" Text="123456789 123456789" />

		<TextBox Grid.Row="0" Grid.Column="1" Margin="2" MaxLength="10" Width="90" />
	</Grid>
</Window>

Expected behavior

It should not show the black vertical bar on the right side of the window.

Actual behavior

It is showing a vertical black bar on the right side of the window.

Regression?

I have tried .NET 4.8, .NET 7 and .NET 8. All produce the same problem.

Known Workarounds

No response

Impact

No response

Configuration

.NET 8, C#, Windows 11 Pro x64

Other information

No response

@hongruiyu
Copy link

You could try setting SnapsToDevicePixels to True

<Window  ... SnapsToDevicePixels="True">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants