none
Help with DatePicker.Value

    General discussion

  • Hello, I am trying to save the value from a datepicker to IsolatedStorage but I am having a hard time...Ive tried to covert it to string and it still doesnt want to work, i also tried declaring a new string named it Date then converted it to string but same result...I tested my code with a textblock.text and it works fine....if anyone can help me out please do... here is my code

    private void ButtonWeight_Click(object sender, System.Windows.RoutedEventArgs e)
            {           
                using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    
                    XDocument _doc = new XDocument();

                    XElement _myDate = new XElement(Convert.ToString(DatePicker1.Value));

                    XAttribute weight = new XAttribute("weight", TextBoxWeight.Text);                

                    _myDate.Add(weight);

                    _doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), _myDate);

                    IsolatedStorageFileStream location = new IsolatedStorageFileStream(Convert.ToString(DatePicker1.Value) + ".weight", System.IO.FileMode.Create, storage);

                    System.IO.StreamWriter file = new System.IO.StreamWriter(location);

                    _doc.Save(file);

                    file.Dispose();

                    location.Dispose();

                    NavigationService.Navigate(new Uri("/Pages/SavedWeights.xaml", UriKind.Relative));

                }
            }

    Thursday, October 06, 2011 5:36 PM

All replies

  • Hi,

    To my knowledge that there is no Value property in DatePicker control, Try SelectedDate property.

    Thursday, October 06, 2011 6:42 PM
  • XElement _myDate = new XElement(Convert.ToString(DatePicker1.Value));

    first of all there is no property like "Value" in datepicker, Use Text or SelectedDate properties as per the requirement.

    In which line of code you are getting the error ?

    Friday, October 07, 2011 1:19 AM
  • Seems you are using any Third Party Date Picker which is having Value property instead of Selected Date.

    Can you please tell me where you are getting Error.

    And also try to use SelectedDate, can you see is there any SelectedValue property.

    Friday, October 07, 2011 3:26 AM
  • hi, i am just using the microsoft 7.1 toolkit....i am not getting any errors but when i launch my app it loads fine then i navigate to the page and when i enter a date and a value then hit the save button my application just quits...so to narrow down why this was happening what i did was i left everything the same but instead of reading in the value from the datepicker i used a textblock and it worked perfectly

    Friday, October 07, 2011 2:09 PM
  • there is no selectedDate property

    Friday, October 07, 2011 2:09 PM
  • i added a reference to the microsoft toolkit then added the name space

    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"

    then used the datepicer as shown below

    <toolkit:DatePicker x:Name="DatePicker3"></toolkit:DatePicker>

    Friday, October 07, 2011 2:11 PM
  • just for testing i also created a new application inserted a textblock and a datepicker and then used the same code to convert it to string and set it as the textblock.text property and that worked

    Friday, October 07, 2011 2:13 PM
  • Hi,

    Do you have the code examples for this because I'm trying to do the same thing (store DatePicker) but it does not work. A little help could be great. Thank you.

    Monday, December 12, 2011 5:08 AM
  • Hi,

    Do you have the code examples for this because I'm trying to do the same thing (store DatePicker) but it does not work. A little help could be great. Thank you.

    wish i could help but i still cannot get it to work the way i want to either....no1 seems to know what is up....what exactly are you trying to do?

    Monday, December 12, 2011 5:53 PM