Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
225
Binding in a DataTemplate - is this possible?
posted

O hai!

I'm trying to get some error-bar like things going on in my xamChart, but I'm not having much luck. 

My XAML looks like mieux (notice the binding in the first TranslateTransform):

        <Chart:XamChart Margin="19,245,23,33" Background="White">

            <Chart:XamChart.Resources>

                <DataTemplate DataType="{x:Type Chart:MarkerTemplate}">

                    <Grid>

                        <Grid.RenderTransform>

                            <TranslateTransform Y="{Binding Bid}" />

                        </Grid.RenderTransform>

                        <Rectangle Height="16" Width="1" Stroke="Blue" />

                        <Rectangle Height="1" Width="6" Stroke="Blue">

                            <Rectangle.RenderTransform>

                                <TranslateTransform Y="8" />

                            </Rectangle.RenderTransform>

                        </Rectangle>

                        <Rectangle Height="1" Width="6" Stroke="Blue">

                            <Rectangle.RenderTransform>

                                <TranslateTransform Y="-8" />

                            </Rectangle.RenderTransform>

                        </Rectangle>

                    </Grid>

                </DataTemplate>

            </Chart:XamChart.Resources>

            <Chart:XamChart.Series>

                <Chart:Series ChartType="ScatterLine" DataSource="{Binding Smile}" DataMapping="ValueX=Strike; ValueY=Fair">

                    <Chart:Series.Marker>

                        <Chart:Marker Foreground="Transparent" UseDataTemplate="True" />

                    </Chart:Series.Marker>

                </Chart:Series>

            </Chart:XamChart.Series>

        </Chart:XamChart>

 

 And I'm binding points in the chart to objects that look a little something like this: 

  class PriceVM : DependencyObject

  {

    public float Strike

    {

      get { return (float)GetValue(StrikeProperty); }

      set { SetValue(StrikeProperty, value); }

    }

 

    // Using a DependencyProperty as the backing store for Strike.  This enables animation, styling, binding, etc...

    public static readonly DependencyProperty StrikeProperty =

        DependencyProperty.Register("Strike", typeof(float), typeof(PriceVM), new UIPropertyMetadata(float.NaN));

 

    public float Bid

    {

      get { return (float)GetValue(BidProperty); }

      set { SetValue(BidProperty, value); }

    }

 

    // Using a DependencyProperty as the backing store for Bid.  This enables animation, styling, binding, etc...

    public static readonly DependencyProperty BidProperty =

        DependencyProperty.Register("Bid", typeof(float), typeof(PriceVM), new UIPropertyMetadata(float.NaN));

 

    public float Ask

    {

      get { return (float)GetValue(AskProperty); }

      set { SetValue(AskProperty, value); }

    }

 

    // Using a DependencyProperty as the backing store for Ask.  This enables animation, styling, binding, etc...

    public static readonly DependencyProperty AskProperty =

        DependencyProperty.Register("Ask", typeof(float), typeof(PriceVM), new UIPropertyMetadata(float.NaN));

 

    public float Fair

    {

      get { return (float)GetValue(FairProperty); }

      set { SetValue(FairProperty, value); }

    }

 

    // Using a DependencyProperty as the backing store for Fair.  This enables animation, styling, binding, etc...

    public static readonly DependencyProperty FairProperty =

        DependencyProperty.Register("Fair", typeof(float), typeof(PriceVM), new UIPropertyMetadata(float.NaN));

  }

But the data binding doesn't get picked up. Is it possible to do this, or am I chasing une hareng rouge (red herring)?