在 WPF 中实现向导进度控制
在 WPF 中是否有实现这样的控件的最佳方法?
我可以轻松复制文本标签和进度条(每个标签上方没有圆形“凸起”),但是我想知道是否已经存在用于在 WPF 中创建此类控件的控件或最佳实践。
Is there a best way to implement a control like this in WPF?
I can easily replicate the text labels and the progress bar (without the circular "bumps" above each label) but I'd like to know if there's a control already out there, or a best practice, for creating this sort of control in WPF.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
很难说这种情况下的最佳实践是什么,但我会这样做。
屏幕截图中的向导控件看起来像是
ProgressBar
和ItemsControl
的组合,在这种情况下,我似乎更容易从ItemsControl
派生并实现进度功能,而不是相反,但这也取决于您希望它如何工作(例如,如果您想要顺利的进度或只是逐一点亮点)。使用
UniformGrid
作为ItemsPanel
和下面的ItemTemplate
,我们得到以下外观(Steps 是一个List 字符串)
将
DropShadowEffect
添加到ItemsPanel
,两个ItemTemplate
的Path
元素和两个DataTriggers
来确定当前项目是显示/隐藏左/右的第一个还是最后一个项目路径
,我们可以得到与您的屏幕截图非常相似的外观ItemsPanel
ItemTemplate
如果您决定使用此选项方法,您可能可以弄清楚如何让其余部分继续进行,例如
DropShadowEffect
),我上传了一个带有名为
WizardProgressBar
的自定义控件的示例项目以及一个使用它的演示项目:https://www.dropbox.com/s/ng9vfi6uwn1peot/WizardProgressBarDemo2.zip?dl=0看起来像这样
有关示例的注意事项
DropShadowEffect< /code> 在进度部分和标题上,或者在每个项目之间画一条细线(如图所示)。我想不出一种简单的方法来摆脱它,所以也许这毕竟不是最好的方法:)
更新
对示例项目进行了一些更改,其中我将演示文稿分成两个
ItemsControls
以消除每个项目之间的细线。现在看起来像这样上传至此处:https://www.dropbox.com/s/ng9vfi6uwn1peot /WizardProgressBarDemo2.zip?dl=0
更新结束
以下是上面示例代码中缺少的部分
IsLastItemConverter
It's hard to say what the best practice is in this case but here is how I would do it.
The wizard control in your screenshot looks like a combination of a
ProgressBar
and anItemsControl
and in this case it seems easier to me to derive fromItemsControl
and implement the progress functionality than the other way around but it also depends on how you want it to work (if you want a smooth progress or just light up the dots one-by-one for example).Using a
UniformGrid
asItemsPanel
and theItemTemplate
below, we get the following look (Steps is aList
of strings)Adding a
DropShadowEffect
to theItemsPanel
, twoPath
elements to theItemTemplate
and twoDataTriggers
to determine if the current item is the first or last item to show/hide the left/rightPath
and we can get a pretty similar look to your screenshotItemsPanel
ItemTemplate
If you decide to use this approach you can probably work out how to get the rest of it going, like
DropShadowEffect
) on the progress-part and not in the textAnyway, I uploaded a sample project with a custom control called
WizardProgressBar
and a demo project using it here: https://www.dropbox.com/s/ng9vfi6uwn1peot/WizardProgressBarDemo2.zip?dl=0It looks like this
Things to note about the sample
DropShadowEffect
on the progress-part and the headers or get a thin line between each item (as seen in the picture). I can't think of an easy way to get rid of it so maybe this isn't the best approach after all :)Update
Made a few changes to the sample project where I split the presentation into two
ItemsControls
to get rid of the thin lines between each item. It now looks like thisUploaded it here: https://www.dropbox.com/s/ng9vfi6uwn1peot/WizardProgressBarDemo2.zip?dl=0
End of Update
And here are the missing parts from the sample code above
IsLastItemConverter
我也做了类似的事情。在 WPF 中这实际上相当简单。基本上我创建了 2 个矩形并将它们重叠。背景中的矩形具有渐变颜色,前景中的矩形是用于覆盖渐变矩形的灰色区域。
只需调整灰色矩形的宽度即可产生条形向右或向左移动的错觉。
下面是我所做的图像以及 XAML。
I did something similar to this too. It's actually fairly easy in WPF. Basically I created 2 rectangles and overlapped them. The rectange in the background has the gradient colors and the rectangle in the foreground is the gray area used to cover up the gradient rectangle.
Simply adjust the width of the gray rectangle to give the illusion of the bar moving right or left.
Below is an image of what I did, along with the XAML.
您可以绘制完整的进度指示器,为进度指示器设置剪切蒙版,并在程序执行期间的适当时间点更改该蒙版或将其与另一个蒙版交换。如果您想发挥真正的创意,您可以制作一个可以定义任意数量的点的控件。
本文向您介绍 Expression 中的通用剪贴蒙版:http://expression.microsoft.com/en- us/cc197119
本文向您展示了一些可能更相关的代码:
http://blog.pixelingene.com/ 2009/02/wpf-using-clipping-masks 动画图/
在此代码中,您可以在运行时轻松调整 RectangleGeometry。
因此,我从所有这些阅读和思考中得到的是,您可能会尝试蓝色进度指示器上的 Clip 属性,并保持背景不变。
这就是我可能会采取的路线。希望这有帮助!
You could draw the full progress indicator, set up a clipping mask for the progress indicator, and either alter or swap that mask with another mask at the appropriate points during your program's execution. If you wanted to get really creative, you could make a control that can define any arbitrary number of points.
This article tells you about generic clipping masks in Expression: http://expression.microsoft.com/en-us/cc197119
This article shows you some code that may be a little more relevant:
http://blog.pixelingene.com/2009/02/animating-graphs-in-wpf-using-clipping-masks/
and in this code, you could easily adjust the RectangleGeometry at runtime.
So what I get from all this reading and pondering is that you'd possibly try the Clip property on your blue progress indicator, and leave the background as-is.
That's the route I would probably take. Hope this helps!