Silverlight 控件绑定和渲染
我正在尝试构建一个 Silverlight4 UserControl 来呈现多个测试和测试运行的结果。我想为每个测试显示一个矩形,总结该测试的一次或多次运行的结果。
我是否可以绑定到通用列表,并让 UserControl 包含绘制矩形内容的所有逻辑,具体取决于测试数量和结果(通过=绿色;失败=红色)?每个结果的宽度取决于测试的数量,因此整个矩形的宽度始终恒定。这是一种用于报告目的的单向绑定。
我不确定这是否可行,或者何时可以调用我的 Render() 方法?
I'm trying to construct a Silverlight4 UserControl to render results of multiple tests and testruns. I want to display a rectangle for each test that summarises the results of one or more runs for that test.
Can I bind to a generic List, and have the UserControl contain all the logic to draw the contents of the rectangle, depending on the number of tests, and the results (pass=green; fail=red)? The width of each result would depend on the number of tests, so that the overall rectangle width was always constant. This is a one-way binding for reporting purposes.
I'm not sure if this is feasible, or when my Render() method could be called?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在尝试想象你想做什么。您想要一个具有多种颜色的矩形来代表测试结果吗?因此,如果您想要的话,可以使用渐变画笔来管理红色区域的位置。
请注意我们如何从 0.2999 变为 0.3000,这将确保您的渐变呈现像素锐度。因此,您的前 29.99% 的测试结果是“通过”,然后 1% 失败,然后其余的通过。
因此,出于绑定目的,您需要找到一种将颜色和偏移值传递给 UserControl 的方法,或者使用当前的通用列表并让 UserControl 根据结果生成 GradientStop。
偏移量会非常有效,因为它们是基于百分比的。你的矩形将始终是 500px(或任何你喜欢的),并且渐变将随之而来。
I'm trying to imagine what you're trying to do. Did you want a single rectangle with multiple colors representing the test results? So, if you want that, then you can use a gradient brush to manage the locations of the red zones.
Notice how we go from .2999 to .3000, this will make sure your gradients appear pixel-sharp. So, your first 29.99% of your test results are "pass", then 1% failed, then the remainder passed.
So for binding purposes, you'll need to figure out a way to pass the color and offset values to your UserControl, or use your current generic list and have the UserControl generate GradientStops based on the results.
The offsets will work great since they are based on percentages. Your rectangle will always be 500px (or whatever you like), and the gradient will follow.