开发者

need to bind a property value in WPF dynamically

this is my code

<Canvas Name="chartCanvas1" ClipToBounds="True" Background="Beige">
      <Canvas.RenderTransform>
           <TransformGroup>
               <ScaleTransform ScaleY="-1" /> 
               <TranslateTransform Y="355" />
           </TransformGroup>
      </C开发者_开发百科anvas.RenderTransform>
</Canvas> 

i need to bind the Y="355" to a value from the code behind class in runtime and convert the coordinate system to the natural coordinate system used in mathematics.

problem is i don't know how to do that. some one please help me out.

regards, rangana.


You could implement a IValueConverter for this that does your conversion between the two coordinate systems. And the bind to it in XAML:

<TranslateTransform Y="{Binding SomeDataProperty Converter={StaticResource myCoordinateConverter}}" />

Alternatively if you'd use MVVM your ViewModel would take the mathematical coordinate from the model, convert it to the WPF coordinate system an provide a property for that where the view (the XAML) can directly bind against.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜