Spacing Question on the * operator for XAML with Grids
So, I just wanted to understand why this was happening in my WPF app as it seems to be adding a "space" or faint line without me wanting it...
I have the following XAML
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication3.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid x:Name="LayoutRoot" ShowGridLines="False" Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" CornerRadius="10,10,0,0" Height="10" Background="Black"/>
<Border Grid.Row="1" Background="Black">
</Border>
<Border Grid.Row="2" CornerRadius="0,0,10,10" Height="10" Background="Black"/>
</Grid>
<StackPanel Grid.Row="1">
<Button&开发者_运维百科gt;Some Button</Button>
</StackPanel>
</Grid>
Which renders the following window...
The problem is if you look closely at the last row connector you will see a faint gray line...
If however I replace the <RowDefinition Height="*"/>
on the inner grid with a fix pixel size (i.e. <RowDefinition Height="300"/>
) the line goes away. Why exactly when I am using the * value does it seem to be adding this "grey line" / "space"?
I think the problem is Anti-Aliasing
- Your effect
- SnapsToDevicePixels="True"
- UseLayoutRounding="False"
- RenderOptions.EdgeMode="Aliased"
It looks like layout rounding problem to me. If you are using WPF 4, try setting UseLayoutRounding="true"
on your outer grid. Else, take a look at SnapToDevicePixels
.
http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.uselayoutrounding.aspx
http://www.wpftutorial.net/DrawOnPhysicalDevicePixels.html
精彩评论