2016-01-13 22 views
0

下面顯示了我的wpf應用程序的一個簡單部分,您可以在其中看到兩個邊框(1.和2.)。WPF:兩個具有純色背景的邊框在頂部有一個醜陋的像素行(與父面板的背景合併顏色)

enter image description here

在3.你可以看到一個精簡版紅線(這是我的問題)。該行從未(明確)在xaml代碼中定義。紅色背景僅在父母網格中定義,並在邊框元素的頂部閃爍。下面是我的代碼:

<Window 
x:Class="BgColorBug.MainWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
Title="MainWindow" Height="200" Width="200" 
WindowStartupLocation="CenterScreen" 
> 
<Grid Background="White"> 
    <Grid.RowDefinitions> 
     <RowDefinition /> 
     <RowDefinition Height="auto" /> 
    </Grid.RowDefinitions> 

    <Grid Grid.Row="1" Background="Red"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="auto" /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 

     <Border 
      Grid.Row="0" 
      Height="4" Background="#1F1F1F" /> 

     <Border 
      Grid.Row="1" 
      Background="#777777" 
      > 
      <WrapPanel 
       Orientation="Horizontal" 
       HorizontalAlignment="Right" 
       > 
       <Button Padding="7" Margin="7">Hello</Button> 
       <Button Padding="7" Margin="7">World</Button> 
      </WrapPanel> 
     </Border> 

    </Grid> 
</Grid> 

當我定義修復行高度(而不是自動值),那麼紅線沒有顯示,所以我認爲這是一個顯示問題(由側邊界1.也有紅線)。

回答

1

雖然我寫了我的問題,我發現that article與我的問題的解決方案。

在最後一個網格上方的任何網格上必須聲明UseLayoutRounding =「True」(因爲該值會被繼承)。

<Grid Grid.Row="1" Background="Red" UseLayoutRounding="True"> 

在知道關鍵字'LayoutRounding'後,我發現this Article on StackOverflow有類似的問題。

在知道LayoutRounding = False的問題後,我不知道不使用它有什麼好處?也許表現? 使用該標誌的最佳做法是什麼?在一些微軟文章中,他們說它在根元素(這是主窗口)上設置它爲真。但如果是這樣,我想知道爲什麼這個標誌默認情況下不是真的。