开发者

Silverlight control binding and rendering

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?


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.

<Rectangle Width="500">
   <Rectangle.Fill>
      <GradientBrush>
          <!-- These can be managed by your user control -->
          <GradientStop Color="Green" Offset=".2999" />
          <GradientStop Color="Red" Offset=".3000" />
          <GradientStop Color="Green" Offset=".3100" />
      </GradientBrush>
   </Rectangle.Fill>
</Rectangle>

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜