madhu kumar
madhu kumar

Reputation: 810

How to bind values programmatically in c# for windows phone?

I need some values to bind in c# as they are posted through XML Serialization to the next screen. In the code below ehvalue3 should be posted through XML. It's working fine when binding is specified in XAML but I need to specify binding in c# code.

How to do this?

private void EHSelect_Click(object sender, RoutedEventArgs e)
        {                
            int ehvalue1 = EHMeterSelector.SelectedItem;
            int ehvalue2 = EHCentimeterSelector.SelectedItem;
            if (ehvalue1 == 0)
            {
                ehvalue1 = EHMeterSelector.DefaultValue;
            }
            EHeight_btn.Content = ehvalue1 + " ft " + ehvalue2+ " in";         

            float ehvalue3 = float.Parse(string.Format("{0}.{1}", ehvalue1.ToString(), ehvalue2.ToString()));      

SaveUser();
        }

Upvotes: 0

Views: 389

Answers (1)

Dutts
Dutts

Reputation: 6191

I recommend you look at something like this guide which should help you.

In a nutshell, you need to:

  • Ensure that your C# class implements INotifyPropertyChanged.
  • That changes to your properties raise an appropriate PropertyChanged event.
  • That the DataContext of your XAML Control is set to the C# class.
  • Binding to properties can then be something like Text="{Binding myProperty,Mode=TwoWay}"

Upvotes: 1

Related Questions