Rangana Sampath
Rangana Sampath

Reputation: 1457

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>
      </Canvas.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.

Upvotes: 0

Views: 152

Answers (1)

bitbonk
bitbonk

Reputation: 49609

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.

Upvotes: 2

Related Questions