Page 1 of 1
More DataBinding
#6
Posted 28 July 2010 - 06:00 AM
Hi Chief,
I checked it with WP7, it is working fine here. Please checkout the code below:
Create a class which implements INotifyPropertyChanged interface.
Now instantiate the above class and set binding for AxisMinimum property as shown below:
After running the application, once you type a value in the TextBox (AxisMinTextBox) field, it will reflect in chart Axis.
I checked it with WP7, it is working fine here. Please checkout the code below:
Create a class which implements INotifyPropertyChanged interface.
public class BindValues : INotifyPropertyChanged
{
public Double AxisMinimum
{
get
{
return _a_min;
}
set
{
_a_min = value;
FirePropertyChanged("AxisMinimum");
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
public void FirePropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
private Double _a_min = 5;
}Now instantiate the above class and set binding for AxisMinimum property as shown below:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
// Set Binding for AxisMinimum property
Binding binding = new Binding();
binding.Source = bindValues;
binding.Path = new PropertyPath("AxisMinimum");
MyChart.AxesY[0].SetBinding(Axis.AxisMinimumProperty, binding);
// Attach TextChanged event with TextBox created in XAML
AxisMinTextBox.TextChanged += new TextChangedEventHandler(AxisMinTextBox_TextChanged);
}
void AxisMinTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
// Set AxisMinimum property of BindValues class
TextBox textBox = sender as TextBox;
if(!String.IsNullOrEmpty(textBox.Text))
bindValues.AxisMinimum = Convert.ToDouble(textBox.Text);
}
// Initialize BindValues class
BindValues bindValues = new BindValues();
}After running the application, once you type a value in the TextBox (AxisMinTextBox) field, it will reflect in chart Axis.
Regards,
Vivek
Team Visifire
Vivek
Team Visifire
#7
Posted 29 July 2010 - 01:33 AM
I'm using the MVVM Light framework
XAML:
ViewModel:
Am I doing something wrong?
XAML:
<vc:Chart Height="350" BorderThickness="0" Theme="Theme1" ScrollingEnabled="False" >
<vc:Chart.AxesX>
<vc:Axis Title="Time of Day (min)" Interval="1" AxisMinimum="{Binding XAxisMinimum}" />
</vc:Chart.AxesX>
<vc:Chart.AxesY>
<vc:Axis Title="Travel Time" AxisType="Primary" />
</vc:Chart.AxesY> ...ViewModel:
public class TrackViewModel : ViewModelBase, ITrackViewModel
{
public double XAxisMinimum {
get { return 100; }
}
}Am I doing something wrong?
#13
Posted 02 August 2010 - 07:37 AM
Hi Chief7,
At present Visifire has some issue while Databinding to custom class through xaml. We will look into the issue. But there is a workaround to bind properties.
For Example:
In code behind
Regards,
Sharmila
Quote
Like I said before, I'm using the MVVMLight framework and avoiding any code in the code behind. Is there any way to set the source via xaml?
At present Visifire has some issue while Databinding to custom class through xaml. We will look into the issue. But there is a workaround to bind properties.
For Example:
<vc:Axis Title="Axis-Y" AxisMinimum="{Binding ElementName=textBox1, Path=Text}"/>In code behind
void textBox1_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox tb = sender as TextBox;
MyChart.AxesY[0].AxisMinimum = Convert.ToDouble(tb.Text);
}
Regards,
Sharmila
Page 1 of 1


Sign In
Register
Help


MultiQuote
