步骤条实现的效果:

步骤条控件是在listbox的基础上实现的。

一、

xaml代码:

  <Window.Resources>
<convert1:StepListBarWidthConverter x:Key="StepListStepWidthConverter" />
<ControlTemplate x:Key="NormalItemTemplate" TargetType="ListBoxItem">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="" />
</Grid.RowDefinitions>
<ContentPresenter HorizontalAlignment="Center" Content="{TemplateBinding Content}" />
<Grid Grid.Row="" Margin="">
<Ellipse
Width=""
Height=""
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="#55DCF5" />
</Grid>
</Grid>
</ControlTemplate>
<Style x:Key="StepListBoxStyle" TargetType="ListBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBox">
<Grid>
<Rectangle
Width=""
Height=""
Margin="0,0,0,8"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Fill="#55DCF5" />
<ItemsPresenter />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <ControlTemplate x:Key="SelectedTemplate" TargetType="ListBoxItem">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="" />
</Grid.RowDefinitions>
<ContentPresenter HorizontalAlignment="Center" Content="{TemplateBinding Content}" />
<Grid Grid.Row="" Margin="">
<Ellipse
Width=""
Height=""
VerticalAlignment="Center"
Panel.ZIndex="">
<Ellipse.Fill>
<SolidColorBrush Color="#FFFFFF" />
</Ellipse.Fill>
</Ellipse>
<Ellipse
Width=""
Height=""
VerticalAlignment="Center"
Panel.ZIndex="">
<Ellipse.Fill>
<SolidColorBrush Color="#225BA7" />
</Ellipse.Fill>
</Ellipse>
<Ellipse
Width=""
Height=""
VerticalAlignment="Center"
Panel.ZIndex="">
<Ellipse.Fill>
<SolidColorBrush Color="#FFFFFF" />
</Ellipse.Fill>
</Ellipse>
</Grid>
</Grid>
</ControlTemplate>
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Width" Value="{Binding RelativeSource={RelativeSource AncestorType=ListBox}, Converter={StaticResource StepListStepWidthConverter}}" />
<Setter Property="FontSize" Value="" />
<Setter Property="FontFamily" Value="SimHei" />
<Setter Property="Foreground" Value="#ACF1FE" />
<Setter Property="Template" Value="{StaticResource NormalItemTemplate}" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Trigger.Setters>
<Setter Property="Template" Value="{StaticResource SelectedTemplate}" />
<Setter Property="FontSize" Value="" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontFamily" Value="SimHei" />
</Trigger.Setters>
</Trigger>
</Style.Triggers>
</Style> </Window.Resources>
<StackPanel Background="SteelBlue">
<ListBox
Margin="0 200 0 0"
x:Name="NavList"
HorizontalAlignment="Center"
BorderThickness=""
Foreground="#225BA7"
IsEnabled="False"
ItemContainerStyle="{StaticResource ListBoxItemStyle}"
SelectedIndex=""
Style="{StaticResource StepListBoxStyle}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel IsItemsHost="False" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem></ListBoxItem>
<ListBoxItem></ListBoxItem>
<ListBoxItem></ListBoxItem>
<ListBoxItem></ListBoxItem>
<ListBoxItem></ListBoxItem>
<ListBoxItem></ListBoxItem> </ListBox>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button Click="Button_Click">下一步</Button>
<Button Margin="100,0,0,0" Click="Button_Click_1">首页</Button>
</StackPanel>
</StackPanel>

各个样式模板介绍:StepListBoxStyle,整个步骤条控件的样式,矩形长条模板。

NormalItemTemplate,未被选中时单个步骤样式。

SelectedTemplate,被选中时单个步骤样式。

ListBoxItemStyle,通过样式和触发器使用模板。

二、需要固定步骤条总长度,根据项数设置步骤条步长,所以需要写个转换器,设置每项长度。

转换器代码:

    class StepListBarWidthConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
ListBox listBox = value as ListBox;
if (listBox==null)
{
return Binding.DoNothing;
}
if (listBox.Items.Count == )
{
return ;
}
return / (listBox.Items.Count - );
} public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}

使用的时候对Listbox的ItemSource和SelectedIndex进行绑定即可。

WPF-自定义实现步骤条控件的更多相关文章

  1. WPF教程002 - 实现Step步骤条控件

    原文:WPF教程002 - 实现Step步骤条控件 在网上看到这么一个效果,刚好在用WPF做控件,就想着用WPF来实现一下 1.实现原理 1.1.该控件分为2个模块,类似ComboBox控件分为Ste ...

  2. WPF自定义LED风格数字显示控件

    原文:WPF自定义LED风格数字显示控件 版权声明:本文为博主原创文章,转载请注明作者和出处 https://blog.csdn.net/ZZZWWWPPP11199988899/article/de ...

  3. 【C#】wpf自定义calendar日期选择控件的样式

    原文:[C#]wpf自定义calendar日期选择控件的样式 首先上图看下样式 原理 总览 ItemsControl内容的生成 实现 界面的实现 后台ViewModel的实现 首先上图,看下样式 原理 ...

  4. WPF自定义控件第一 - 进度条控件

    本文主要针对WPF新手,高手可以直接忽略,更希望高手们能给出一些更好的实现思路. 前期一个小任务需要实现一个类似含步骤进度条的控件.虽然对于XAML的了解还不是足够深入,还是摸索着做了一个.这篇文章介 ...

  5. C#开发step步骤条控件

    现在很多的javascript控件,非常的不错,其中step就是一个,如下图所示: 那么如何用C#来实现一个step控件呢? 先定义一个StepEntity类来存储步骤条节点的信息: public c ...

  6. WPF 自定义ItemsControl/ListBox/ListView控件样式

    一.前言 ItemsControl.ListBox.ListView这三种控件在WPF中都可作为列表信息展示控件.我们可以通过修改这三个控件的样式来展示我们的列表信息. 既然都是展示列表信息的控件,那 ...

  7. WPF 自定义TextBox带水印控件,可设置圆角

    一.简单设置水印TextBox控件,废话不多说看代码: <TextBox TextWrapping="Wrap" Margin="10" Height=& ...

  8. 4.自定义view-进度条控件

    1.效果 2.实现原理 画圆,画圆弧,画文字 外部控制进度,通过invalidate()方法更新 核心代码: @Override protected void onDraw(Canvas canvas ...

  9. Photoshop和WPF双剑配合,打造炫酷个性的进度条控件

    现在如果想打造一款专业的App,UI的设计和操作的简便性相当重要.UI设计可以借助Photoshop或者AI等设计工具,之前了解到WPF设计工具Expression Blend可以直接导入PSD文件或 ...

随机推荐

  1. 关于在 ASP.NET 的 Global.asax 中 Application_Error 方法内,设置跳转到自定义错误页无效的问题

    转自:https://www.cnblogs.com/OpenCoder/p/5070645.html 在 Global.asax 中的 Application_Error 方法中,使用 Respon ...

  2. 获取BOM标准用量

    Select dbms_aw.eval_number(listagg(' 1' ||                                        sys_connect_by_pat ...

  3. 抓包工具 tcpdump 用法说明

    tcpdump采用命令行方式对接口的数据包进行筛选抓取,其丰富特性表现在灵活的表达式上. 不带任何选项的tcpdump,默认会抓取第一个网络接口,且只有将tcpdump进程终止才会停止抓包. 例如: ...

  4. MVC 、MTV 模式

    著名的MVC模式:所谓MVC就是把web应用分为模型(M),控制器(C),视图(V)三层:他们之间以一种插件似的,松耦合的方式连接在一起. 模型负责业务对象与数据库的对象(ORM),视图负责与用户的交 ...

  5. ssh-agent,ssh-add 命令

    centos 6.9 下测试: ssh-agent是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管. eval `ssh-agent -s` ssh-a ...

  6. CodeForces 1236D(模拟)

    题意 https://vjudge.net/problem/CodeForces-1236D 最近,爱丽丝得到了一个新玩偶.它甚至可以走路! 爱丽丝为玩偶建造了一个迷宫,并想对其进行测试.迷宫具有n行 ...

  7. 3.Java基础_Java变量

    /* 变量定义格式 数据类型 变量名=变量值 基本数据类型: byte,short,int,long,float,double,char,boolean 变量的使用: 取值格式: 变量名 修改值格式: ...

  8. Kvm命令集管理虚拟机

    KVM虚拟机配置文件位置 [root@localhost ~]# ll /etc/libvirt/qemu/ 总用量 drwxr-xr-x root root 12月 : autostart drwx ...

  9. python 读写.tar.gz文件 -- UnicodeDecodeError

    在用pip install 安装库的时候,偶尔会出现编码错误(如:UnicodeDecodeError: 'gbk' codec can't decode byte),对此我们可先将包下载下来(一般为 ...

  10. day82_10_31celery的使用

    1.缓存 当一些数据需要固定地且频繁访问数据库时,需要使用到接口缓存. 以轮播图为例,每个用户都会访问首页,首页的轮播图长时间不会改变,所以可以使用cache,将固定数据保存到缓存中(redis),第 ...