代码之家  ›  专栏  ›  技术社区  ›  Paul Prewett

绑定矩形几何体。矩形不显示矩形

  •  3
  • Paul Prewett  · 技术社区  · 14 年前

      <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>
    

    请注意此处注释的矩形几何体。当我取消对它的注释并注释掉绑定的矩形几何体时,这种方法非常有效。当然,它不会随着分数的变化而改变大小。

      ...
      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;
      }
      ...
    

    有什么想法吗?

    谢谢, 保罗

    1 回复  |  直到 14 年前
        1
  •  3
  •   John Bowen    14 年前

    您的转换器正在返回一个矩形几何体,然后尝试将其指定给矩形几何体上Rect类型的Rect属性。去掉转换器中的“output”对象,只返回Rect本身。