如何仅选择线形而不是选择大方块

时间:2016-03-02 03:58:01

标签: wpf xaml listview selecteditem

我正在开发一个WPF项目,该项目的ListBox绑定到一个集合。此ListBox显示画布中的元素,因为这些元素为ellipseslines

我正在开发一个应用程序,我可以在其中绘制实体(ellipses)和连接器(lines)。那已经有效了。

我还希望能够选择ellipseline我已经可以执行此操作,因为此功能由ListBox提供。但是,当我选择一条线时,选中的线看起来像一个丑陋的大蓝色方块!

有没有办法只选择纯线?

以下是我当前的ListBox实现的样子:

<ListBox ItemsSource="{Binding Elements}" >            
    <ItemsControl.ItemContainerStyle>
        <Style>
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                         Color="Transparent"/>
            </Style.Resources>
            <Setter Property="Canvas.Left" Value="{Binding CanvasLeft}" />
            <Setter Property="Canvas.Top" Value="{Binding CanvasTop}" />
            <Setter Property="Panel.ZIndex" Value="{Binding ZIndex, Mode=TwoWay}" />
        </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.Resources>
        <DataTemplate DataType="{x:Type vm:EntityViewModel}" >
            <Viewbox>
                <Grid>
                    <Ellipse myb:DraggableBehavior.IsDraggingEnabled="True"
                            Stroke="Black" 
                            Width="{Binding ShapeWidth, Mode=TwoWay}" 
                            Height="{Binding ShapeHeight, Mode=TwoWay}" 
                            Canvas.Left="{Binding X1, Mode=TwoWay}"
                            Canvas.Top="{Binding Y1, Mode=TwoWay}"
                            Fill="{Binding Background}" 
                            Panel.ZIndex="{Binding ZIndex, Mode=TwoWay}" >
                    </Ellipse>
                    <TextBlock Text="{Binding StatePropertiesViewModel.Name}"
                           HorizontalAlignment="Center"  
                           TextAlignment="Center" 
                           VerticalAlignment="Center" />
                </Grid>
            </Viewbox>
        </DataTemplate>
        <DataTemplate DataType="{x:Type vm:LineViewModel}" >
            <Line X1="{Binding X1, Mode=TwoWay}"
                  Y1="{Binding Y1, Mode=TwoWay}"
                  X2="{Binding X2, Mode=TwoWay}"
                  Y2="{Binding Y2, Mode=TwoWay}"
                  Stroke="{Binding Color, Mode=TwoWay}"
                  StrokeThickness="{Binding Thickness, Mode=TwoWay}"
                  Panel.ZIndex="{Binding ZIndex, Mode=TwoWay}"
                  />
        </DataTemplate>
    </ItemsControl.Resources>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>            
</ListBox>

更新

遵循@ AbhinavSharma的建议后:

    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                         Color="Transparent"/>
    </Style.Resources>

现在似乎看不到蓝色方形选区,它看起来更好。然而,它仍然存在,因为,例如,如果我在Line上有Ellipse形状,我无法选择椭圆,因为不可见的选定线区域仍然存在。即点击它时我选择的是线,而不是椭圆。那么,有没有办法将选择区域缩小到形状本身的区域?

提前致谢。

0 个答案:

没有答案
相关问题