开发者

Binding RectangleGeometry.Rect doesn't show the rectangle

开发者 https://www.devze.com 2023-01-08 13:40 出处:网络
I\'m having an issue trying to bind to a RectangleGeometry\'s Rect property.The basic idea here is that I\'m attempting to bind a clip mask to control the visualized height of a pseudo-chart object.He

I'm having an issue trying to bind to a RectangleGeometry's Rect property. The basic idea here is that I'm attempting to bind a clip mask to control the visualized height of a pseudo-chart object. Here's the XAML:

  <Path x:Name="_value" Fill="{DynamicResource PositiveColorBrush}" Data="F1 M10,55 C10,57.75 7.75,60 5,60 2.25,60 0,57.75 0,55 L0,5 C0,2.25 2.25,0 5,0 7.75,0 10,2.25 10,5 L10,55 z">
     <Path.Clip>
        <!-- SECOND NUMBER CONTROLS THE HEIGHT : SCALE OF 0-60 REVERSED -->
        <!--<RectangleGeometry Rect="0,22.82,10,60"/>-->
        <RectangleGeometry 
           Rect="{Binding Score, Converter={StaticResource ChartBarScoreConverter}}" />
     </Path.Clip>
  </Path>

Note the commented RectangleGeometry there. That works perfectly when I uncomment it and comment out the bound RectangleGeometry. Of course, it won't change size when the Score changes, though.

Now, if I place a breakpoint in the ChartBarScoreConverter, I get the proper value and return a new RectangleGeometry object of the exact same specs as the commented out one there. Here's the short code of the converter:

  ...
  public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  {
     RectangleGeometry output = new RectangleGeometry();
     double score = 60; //0
     if (Common.IsNumeric(value))
     {
        score = System.Convert.ToDouble(value) * .60;//scale is 0-60
        score = 60 - score;//reversed (=
     }
     output.Rect = new Rect(0, score, 10, 60);
     return output;
  }
  ...

When the app is run, it simply doesn't show the clip. As I said, I put a breakpoint in the converter and have verified that it's called and that an object o开发者_JS百科f the correct size is returned... but it just doesn't appear in the view.

Any ideas?

Thanks, Paul


Your converter is returning a RectangleGeometry which you're then trying to assign to the Rect property of type Rect on a RectangleGeometry. Get rid of the "output" object in the converter and just return the Rect itself.

0

精彩评论

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