wpf linewidth linestyle combobox(线宽选择器)

wpf没有默认的线宽、线样式选择器,不过通过自制可以达到如下效果:

代码如下:

<StackPanel Orientation="Horizontal" Margin="0 10 0 0">
                    <TextBlock Margin="13 0 0 0" VerticalAlignment="Center">Line Style:</TextBlock>
                    <ComboBox Name="combox1" Width="120" Margin="5 0 0 0" VerticalAlignment="Center" HorizontalAlignment="Left" Background="White" SelectedIndex="0" Height="20">
                        <ComboBoxItem Margin="0 5 0 5">
                            <StackPanel>
                                <Line X1="5" X2="110"  Width="100"  Margin="10 5 10 5" StrokeDashArray="4 2 0.5 1"  StrokeThickness="3" Stroke="Black" VerticalAlignment="Center" HorizontalAlignment="Left"></Line>
                            </StackPanel>
                        </ComboBoxItem>
                    </ComboBox>
                </StackPanel>

可以通过控制line控件属性来达到画线的虚实、粗细等效果

一、line.StrokeThickness   描述线的粗细  

二、line.StrokeDashArray 是一个双精度字符串,指示用于勾勒形状轮廓的虚线和间距的样式  

例如 StrokeDashArray="4 2 0.5 1"    表示  第一段实线长为4  间隔为2  第二段实线长0.5  间隔为1以此类推 若无后续则循环

三、Stroke="Black"   线的颜色

注意:comboboxitem中线控件要加上stankpanel  否则显示不出来

 

demo如下:https://download.csdn.net/download/realzuile/12001177

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章