5 Replies - 9053 Views - Last Post: 20 September 2012 - 10:04 AM

#1 Quizton  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 18-April 12

dynamicaly changing binding from 2way to 1 not saving correctly

Posted 18 September 2012 - 05:56 PM

Having a strange issue here !

I got xaml textbox that is 2 way bound to the db one for editing and one page for displaying on a pivot page.

well recently I decided to have 1 of the textboxes on the Add edit page to be filled in by sending the object to it

so since twoway will not let me send that object on the fly for somereason I had c# change it to oneway then I send the object across and it fills the box.

Problem here is now the record wont save and display?

so I change it back to 2way right b4 the submit to db but that clears the text i sent it cause it didnt save and load correctly.

also if i keep it 2way and enter the text manually it will however save and load correclty?

any insight on this would be great! thanks

Is This A Good Question/Topic? 0
  • +

Replies To: dynamicaly changing binding from 2way to 1 not saving correctly

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: dynamicaly changing binding from 2way to 1 not saving correctly

Posted 20 September 2012 - 05:36 AM

Posting your code would definitely help out. What do you mean by this?

Quote

so since twoway will not let me send that object on the fly for somereason I had c# change it to oneway then I send the object across and it fills the box.


Do you mean binding doesn't work when in 2-Way?
Was This Post Helpful? 0
  • +
  • -

#3 Quizton  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 18-April 12

Re: dynamicaly changing binding from 2way to 1 not saving correctly

Posted 20 September 2012 - 07:07 AM

yes the textbox saves and displays to a pivotpage using 2way binding.

but with 2 way I cant send a textobject automatically to fill the box during navigatedTo but i can manually enter it and save fine

so I made a adjustment thru c# to change the binding to either 1way or 1time on navigated to then sends and fills the box. now the problem there is it wont save to db cause i need it 2way to display the text on the pivotpage.

I try to swap it back to 2way wile validating and saving but it seems to clear it.

Is it possible to change from one way to 2way without losing the filled text? Or even fill a 2wayboundbox without needing to change it



I can show my xaml and c# if this still sounds a bit unclear
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: dynamicaly changing binding from 2way to 1 not saving correctly

Posted 20 September 2012 - 07:35 AM

Yes, please show your code. Show what works, and show what doesn't work.
Was This Post Helpful? 0
  • +
  • -

#5 Quizton  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 18-April 12

Re: dynamicaly changing binding from 2way to 1 not saving correctly

Posted 20 September 2012 - 09:26 AM

Ok heres the control
<TextBox Text="{Binding FirstData, Mode=TwoWay}" VerticalAlignment="Center"
                        x:Name="firstData" Grid.Column="1" 
                        Margin="23,0,8,0" Grid.Row="9"/>



viewmodel
[Column]
        public string FirstData
        {
            get { return firstData; }
            set
            {
                InvokePropertyChanging(new PropertyChangingEventArgs("FirstData"));
                firstData = value;
                InvokePropertyChanged(new PropertyChangedEventArgs("FirstData"));
            }
        }



action to send the text to box
private void button1_Click(object sender, RoutedEventArgs e)
        {
            string aande = "/AEDP.xaml?customerId=" + ((Customers)this.DataContext).CustomersID + "&t1=" + this.firstData.Text;
            NavigationService.Navigate(new Uri(aande, UriKind.Relative));



navigation To
if (this.NavigationContext.QueryString.ContainsKey("customerId"))
            {
                var customer = GetCustomers(Int64.Parse(this.NavigationContext.QueryString["customerId"]));
                this.DataContext = customer;
            }
            {
                if (this.NavigationContext.QueryString.ContainsKey("t1")) { this.firstData.Text = this.NavigationContext.QueryString["t1"]; }
                base.OnNavigatedTo(e);


now when I send the text above it wont display wile 2way binded .. but can save a manual typed in one no prob.
How can i fill that box wile 2waybinded? or was changing it to oneway and then filling then change back after submiting to db be a decent way to get that done?
Was This Post Helpful? 0
  • +
  • -

#6 Quizton  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 49
  • Joined: 18-April 12

Re: dynamicaly changing binding from 2way to 1 not saving correctly

Posted 20 September 2012 - 10:04 AM

private void Button_Click(object sender, RoutedEventArgs e)
         {
             Binding binding = new Binding("Text") { Mode = BindingMode.OneWay, Source = textblock };
             textbox.SetBinding(TextBox.TextProperty, binding);
         }


this is a bit i found thru googling and is what i adapted to use to change the control from 2way to oneway

then i filled the box

but still wont save and display correctly until its 2way bound to pivotpage again so i changed it back to 2way but the text wont follow the change.


I dont see why Id have to go this far to achieve something this simple lol why wont my 2way bound textbox take a dynamicaly fed text to it ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1