我在WPF中有一个Grid。网格具有透明背景(必要),每个单元格可能具有不同颜色的纯色背景,或者可能没有背景。当我在这些单元格中放置任意内容时,当两个相邻的单元格都具有彩色背景(相同或不同的颜色,无关紧要)时,通常(并且不可预测地)将它们分开的细透明线,允许您通过网格查看那条线。
有谁知道如何解决这个问题?
编辑:我想在我的问题中提及它,但我已尝试在任何地方和任何地方启用SnapsToDevicePixels,但无济于事。
答案 0 :(得分:1)
在没有看到任何代码的情况下,我猜测你需要SnapsToDevicePixels网格中的元素。
答案 1 :(得分:1)
这会产生同样的问题,但可能不是完全相同的原因。尽管如此,如果我们能解决这个问题,它可能会暗示你的问题。
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="3*" />
<RowDefinition Height="3*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Background="PaleGoldenrod" />
<Label Grid.Column="1" Grid.Row="0" Background="White" />
<Label Grid.Column="2" Grid.Row="0" Background="PaleGoldenrod" />
<Label Grid.Column="0" Grid.Row="1" Background="White" />
<!-- This is in the significant cell -->
<Label Grid.Column="1" Grid.Row="1" x:Name="SizeChangeLabel" Background="PaleGoldenrod">
Watch this cell
</Label>
<Label Grid.Column="2" Grid.Row="1" Background="White" />
<Label Grid.Column="0" Grid.Row="2" Background="PaleGoldenrod" />
<Label Grid.Column="1" Grid.Row="2" Background="White" />
<Label Grid.Column="2" Grid.Row="2" Background="PaleGoldenrod" />
<Button x:Name="ReduceContentSize" Grid.Row="3" Grid.Column="0" Click="ReduceContentSize_Click">Reduce</Button>
<Button x:Name="IncreaseContentSize" Grid.Row="3" Grid.Column="1" Click="IncreaseContentSize_Click">Increase</Button>
<TextBlock Grid.Row="3" Grid.Column="2" Foreground="White">
The window is black
</TextBlock>
</Grid>
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="3*" />
<RowDefinition Height="3*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Background="PaleGoldenrod" />
<Label Grid.Column="1" Grid.Row="0" Background="White" />
<Label Grid.Column="2" Grid.Row="0" Background="PaleGoldenrod" />
<Label Grid.Column="0" Grid.Row="1" Background="White" />
<!-- This is in the significant cell -->
<Label Grid.Column="1" Grid.Row="1" x:Name="SizeChangeLabel" Background="PaleGoldenrod">
Watch this cell
</Label>
<Label Grid.Column="2" Grid.Row="1" Background="White" />
<Label Grid.Column="0" Grid.Row="2" Background="PaleGoldenrod" />
<Label Grid.Column="1" Grid.Row="2" Background="White" />
<Label Grid.Column="2" Grid.Row="2" Background="PaleGoldenrod" />
<Button x:Name="ReduceContentSize" Grid.Row="3" Grid.Column="0" Click="ReduceContentSize_Click">Reduce</Button>
<Button x:Name="IncreaseContentSize" Grid.Row="3" Grid.Column="1" Click="IncreaseContentSize_Click">Increase</Button>
<TextBlock Grid.Row="3" Grid.Column="2" Foreground="White">
The window is black
</TextBlock>
</Grid>
单击事件会调整中心单元格中标签的MinWidth。当你碰到它时,你会得到我认为与你的问题相同的行。
private const double _sizeChangeAmount = 150;
private void IncreaseContentSize_Click(object sender, RoutedEventArgs e)
{
SizeChangeLabel.MinWidth = SizeChangeLabel.ActualWidth + _sizeChangeAmount;
SizeChangeLabel.MinHeight = SizeChangeLabel.ActualHeight + _sizeChangeAmount;
}
private void ReduceContentSize_Click(object sender, RoutedEventArgs e)
{
if (SizeChangeLabel.MinWidth > 150)
SizeChangeLabel.MinWidth = SizeChangeLabel.ActualWidth - _sizeChangeAmount;
if (SizeChangeLabel.MinHeight > 150)
SizeChangeLabel.MinHeight = SizeChangeLabel.ActualHeight - _sizeChangeAmount;
}
这是一个合理的近似值,可以帮助找到解决方案吗?