473,499 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Binding after data context is changed

2 New Member
Hi,

I have a strange problem.

I have a WPF screen on which I have an extended TextBox that makes some conversions in some cases.That property is bound to a property on view model.

When the data context is changed then the conversions are reevaluated. When reevaluated my extended TextBox has the new data context but the BindingOperations.GetBindingExpression(textBox, dpproperty).DataItem is still having the old data context.

Maybe the conversion that I make is too early after changing the data context?

Usually the data context is not changed into the whole screen so the bindings to be reevaluated?

Thanks!
May 29 '13 #1
3 14252
Sl1ver
196 New Member
I would put the data into a string. The way im doing it here means that the TextData is updated everytime something changes from either end(front or back).




Expand|Select|Wrap|Line Numbers
  1.  private string textData;
  2.         public string TextData
  3.         {
  4.             get { return textData; }
  5.             set
  6.             {
  7.                 textData= value;
  8.                 OnNotifyPropertyChanged("TextData");
  9.             }
  10.         }
extend your class with
Expand|Select|Wrap|Line Numbers
  1. public class YourClassExtended : NotificationBase
  2. {
  3. }
and create that NotificationBase class
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.ComponentModel;
  3. using System.Windows;
  4.  
  5. namespace StatsTool.AddIns.Models
  6. {
  7.     public class NotificationBase : INotifyPropertyChanged
  8.     {
  9.         protected void OnNotifyPropertyChanged(string p)
  10.         {
  11.             if (PropertyChanged != null)
  12.             {
  13.                 PropertyChanged(this, new PropertyChangedEventArgs(p));
  14.             }
  15.         }
  16.  
  17.         public bool IsDesignTime
  18.         {
  19.             get
  20.             {
  21.                 return (Application.Current == null) || (Application.Current.GetType() == typeof(Application));
  22.             }
  23.         }
  24.  
  25.         #region INotifyPropertyChanged Members
  26.  
  27.         public event PropertyChangedEventHandler PropertyChanged;
  28.  
  29.         #endregion
  30.     }
  31. }
May 30 '13 #2
florin2905
2 New Member
The bindings are refreshed into the whole tree when data context is changed.

But in my case I have some bindings on the template of my extended TextBox.

Here the DataContext is changed with some delay after the control where is used triggers the DataContext event, so the bindings are refreshed before the DataContext from my extended TextBox template is really changed, so the binding is still pointing to the old DataContext.
May 30 '13 #3
Frinavale
9,735 Recognized Expert Moderator Expert
I've seen this happen in someone else's code before when they were not binding to the correct item.

For example, they were supposed to be binding to the DataContext of the page, but they were actually binding to something like the DataContext of a parent element whose DataContext was the page.

I'm not entirely sure what was happening, but the result was similar: the data context changed but the child element was still holding onto the old object.

After I fixed the bindings, the problem went away.

Your problem might be trickier than the one I fixed a few weeks ago.

-Frinny
May 30 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1528
by: Jonathan Lee | last post by:
Hello everybody Why I try to binding data from sqlserver to a comboBox that display System.data.dataRowView in the comboBox? Using following codes string sQueryDetailCatalog = "Select dname...
0
1739
by: ani | last post by:
Hi, I have a datalist control and within the Itemplate I have a radiobuttonlist control . I am binding data to the datalist control in Page_load . Also I have sqldatareader object that needs...
0
1255
by: HNguyen | last post by:
Hi, I have a problem of binding data from XQuery to a dataset. Here is the program I've extracted from 4guysfromrolla.com. This program read data from an XML file (Employees.xml) and performed...
5
4202
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
1
1314
by: Laura K | last post by:
Can someone tell me where I went wrong. This is my code for binding data to a datalist. <script language="vb"> Sub Page_Load(Src As Object, e As EventArgs) Dim Con As New...
1
1972
by: Frank Yamrick | last post by:
I am trying to program an application that requires a large number of screnes that are very similar in the respect that all the bottons and labels interact with each other with the same...
3
7227
by: abc my vclass | last post by:
There are some programs written on .NET 1.1. These applications are apply n-tiers contains Data Access Layers or Business Logic Layer. Now, our company upgrade to .NET 2.0 and enhance or rewrite...
2
1856
by: sureshgv | last post by:
SqlConnection cn=new SqlConnection ("User ID=sa;Initial Catalog=usermodule;Data Source=NEW5"); SqlDataAdapter da=new SqlDataAdapter (Application.ToString(),cn); DataSet ds=new DataSet();...
3
2430
by: Max | last post by:
Hello, I made a windows form with a combo box and 4 text boxes. All 5 objects should get their data from a data set which is populated in the form load method. The combo box has item ids. When...
2
4163
by: pavanip | last post by:
Hi, I have a problem with binding data to dropdownlist from database in alphabetical order. My database contains some fields like All,Air,Airline,Books,Cars etc. There are 2 dropdown...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.