2
<Window x:Class="WpfApp1.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"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Border Background="Red">
<Border BorderThickness="10" BorderBrush="Black" Background="Black"/>
</Border>
</Grid>
</Window>
產生以下輸出(.NET 4.6.1時,Windows 10):
紅線不應該存在。它似乎是第二個邊界的邊界和第二個邊界的背景之間的差距。我嘗試將SnapsToDevicePixels
設置爲True
,但它不會更改。
UPDATE
正如答案建議,RenderOptions.EdgeMode="Aliased"
似乎解決了這個問題。但事實上,我認爲最好突出一個WPF中的錯誤。因爲現在,下面的代碼:
<Window x:Class="WpfApp1.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"
RenderOptions.EdgeMode="Aliased"
SnapsToDevicePixels="True"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Border Background="Red">
<Border Margin="10" BorderThickness="1" BorderBrush="Black">
<Grid Background="Black"/>
</Border>
</Border>
</Grid>
</Window>
我在WPF項目中複製了你的代碼,並沒有得到那條紅線,你可能有其他的東西改變你的視覺效果。我想你沒有包括所有的代碼來簡化問題。 – Tuco
我將其複製到VS2015中的一個全新項目中,並顯示在那裏。編輯:只有設計模式,當我運行它沒有紅色。 –
你正在使用W10,我想@AdamSills也是,我使用的是W7,所以它與操作系統如何處理視覺相關,我對該領域無知 – Tuco