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
345
Trouble binding properties of the XamChart
posted

Hi,

I'm not sure what I am doing wrong here.  Could you please help me.  I'm trying to bind various properties of an XamChart and it seems to ignore the returned result.  Underneath is an example :

<igCA:Axis.Stripes>
      <igCA:Stripe Unit="{Binding Path=SelectedValue, Converter={StaticResource CrossingConverter}, ElementName=AccountComboBox, Mode=Default}"/>
</igCA:Axis.Stripes>

[ValueConversion(typeof(object), typeof(Double))]
public class CrossingConverter : IValueConverter {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            
if (value == null || ((Account)value).PortfolioAccounts == null)
                  
return (Double)100;
            
else
                  
return (Double)Math.Round(((Account)value).PortfolioAccounts.InitialValue, 0);
      }

      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            
return null;
      }
}

The value converter code is getting called and returning a value, however whenever I look at the value stored in the Unit it is always 0. 

Thanks,

Graeme

PS.  XamChart is looking like it will be a very good product.

  • 28496
    Offline posted

    i tried this on my machine ... simplified in a few places... following is the complete solution. 

     <Window x:Class="WpfApplication2.Window1"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:igCA="clr-namespace:Infragistics.Windows.Chart;assembly=Infragistics3.Wpf.Chart.v7.2"

    xmlns:local="clr-namespace:WpfApplication2"

    Title="Window1" Height="300" Width="300">

    <Window.Resources>

    <local:CrossingConverter x:Key="CrossingConverter1" />

    </Window.Resources>

    <Canvas>

    <ComboBox x:Name="AccountComboBox" Width="100" Height="25" />

    <igCA:XamChart Width="250" Height="250" Canvas.Top="30">

    <igCA:XamChart.Axes>

    <igCA:Axis AxisType="PrimaryX">

    <igCA:Axis.Stripes>

    <igCA:Stripe Unit="{Binding Path=SelectedValue, Converter={StaticResource CrossingConverter1}, ElementName=AccountComboBox, Mode=Default}" />

    </igCA:Axis.Stripes>

    </igCA:Axis>

    </igCA:XamChart.Axes>

    </igCA:XamChart>

    </Canvas>

    </Window>

     

    using System;

    using System.Collections.Generic;

    using System.Globalization;

    using System.Windows.Data;

    using System.Windows;

    namespace WpfApplication2

    {

    /// <summary>

    /// Interaction logic for Window1.xaml

    /// </summary>

    public partial class Window1 : Window

    {

    public Window1()

    {

    InitializeComponent();

    this.AccountComboBox.ItemsSource = new List<Account>

    {

    new Account { Name = "John", Value = 1},

    new Account { Name = "Paul", Value = 2},

    new Account { Name = "George", Value = 3},new Account { Name = "Ringo", Value = 4}

    };

     

    }

     

    }

    public class Account

    {

    public string Name { get; set; }

    public double Value { get; set; }

    public override string ToString()

    {

    return Name + " " + Value;

    }

    }

    public class CrossingConverter : IValueConverter

    {

    #region IValueConverter Membersobject IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)

    {

    Account acct = value as Account;

    if (acct != null)

    {

    return acct.Value;

    }

    return null;

    }

    object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

    {

    return null;

    }

    #endregion

    }

    }