StackPanel在每个子控件之间绘制工件

时间:2009-10-17 15:42:44

标签: wpf c#-3.0 border stackpanel

我正在尝试在两端画一个半圆形的矩形。我也试图将左半部分与右半部分颜色不同的矩形分开。我已经设法使用堆栈面板和CombinedGeometry来完成此操作,如下例所示。但是,下面的代码在堆栈面板中的每个控件之间绘制一条线。我已经尝试了几件事来移除它或画它。有谁知道如何删除这条线,我怀疑是边界,还是有更好的方法?我试图只添加控件而不是边框​​内的控件,但它没有什么区别。 感谢

<UserControl x:Class="xxx"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Orientation="Horizontal" DataContext="{Binding ElementName=InfoControl, Path=.}">
    <Border Background="White" BorderThickness="0">
        <Path Fill="LightBlue">
            <Path.Data>
                <CombinedGeometry GeometryCombineMode="Intersect">
                    <CombinedGeometry.Geometry1>
                        <EllipseGeometry Center="15,15" RadiusX="15" RadiusY="15"/>
                    </CombinedGeometry.Geometry1>
                    <CombinedGeometry.Geometry2>
                        <RectangleGeometry Rect="0 0 15 30"/>
                    </CombinedGeometry.Geometry2>
                </CombinedGeometry>
            </Path.Data>
        </Path>
    </Border>
    <Border Background="LightBlue" BorderThickness="0">
        <TextBlock x:Name="nameTextBlock" Foreground="SteelBlue" VerticalAlignment="Center" FontSize="16" Margin="0 0 5 0">-</TextBlock>
    </Border>
    <Border Background="CornflowerBlue" BorderThickness="0">
        <TextBlock x:Name="dataTextBlock" Foreground="White" VerticalAlignment="Center" FontSize="16" Margin="5 0 0 0">-</TextBlock>
    </Border>
    <Border Background="White" BorderThickness="0">
        <Path Fill="CornflowerBlue">
            <Path.Data>
                <CombinedGeometry GeometryCombineMode="Intersect">
                    <CombinedGeometry.Geometry1>
                        <EllipseGeometry Center="0,15" RadiusX="15" RadiusY="15"/>
                    </CombinedGeometry.Geometry1>
                    <CombinedGeometry.Geometry2>
                        <RectangleGeometry Rect="0 0 30 30"/>
                    </CombinedGeometry.Geometry2>
                </CombinedGeometry>
            </Path.Data>
        </Path>
    </Border>
</StackPanel>

1 个答案:

答案 0 :(得分:1)

SnapsToDevicePixel上的true设置为StackPanel

<StackPanel SnapsToDevicePixels="True" ...>

阅读this MSDN article以获取解释。