开发者

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...

Spacing Question on the * operator for XAML with Grids

The problem is if you look closely at the last row connector you will see a faint gray line...

Spacing Question on the * operator for XAML with Grids

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

  1. Your effect
  2. SnapsToDevicePixels="True"
  3. UseLayoutRounding="False"
  4. RenderOptions.EdgeMode="Aliased"

    Spacing Question on the * operator for XAML with Grids


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜