|
I've tried doing that but nothing has changed. I used the example from INotifyPropertyChanged on MSDN for a template. Here is a snippet of my code:
public class SubtitleItem : IComparable<SubtitleItem>, INotifyPropertyChanged
{
private TimeSpan _TimeCodeStart;
public TimeSpan TimeCodeStart
{
get { return _TimeCodeStart; }
set
{
if (_TimeCodeStart != value)
{
_TimeCodeStart = value;
NotifyPropertyChanged("TimeCodeStart");
}
}
}
private TimeSpan _TimeCodeEnd;
public TimeSpan TimeCodeEnd
{
get { return _TimeCodeEnd; }
set
{
if (_TimeCodeEnd != value)
{
_TimeCodeEnd = value;
NotifyPropertyChanged("TimeCodeEnd");
}
}
}
public TimeSpan TimeCodeDuration
{
get { return TimeCodeEnd - TimeCodeStart; }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
What am I missing?
<div class="ForumMod">modified on Wednesday, April 30, 2008 7:00 PM</div>
|
|
|
|
|
Can you please post the XAML so we can see what you are doing in that code.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
|
Give this minor tweek a go:
private TimeSpan _TimeCode;
public TimeSpan TimeCode
{
get { return _TimeCode; }
set
{
_TimeCode = value;
NotifyPropertyChanged("TimeCode");
NotifyPropertyChanged("TimeCodeCalc");
}
}
Since TimeCodeCalc is ready only, you just need to tell the UI that it changed. Presto, you are in business.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Thanks, that's working.
I guess I misunderstood how this process worked. I thought you informed the system of what changed then it would automagically know that the whole object had changed and needed to be updated.
But the way it actually seems to work looks like there are plenty of ways for bugs to creep in. For instance, in my real project, the property IsModified will have to be notified from every field that can be changed.
Are there any solutions to just hardcoding a bunch of these NotifyPropertyChanged in every editable field?
|
|
|
|
|
If you have a field that changes anytime other properties are changed, you can raise that event in the PropertyChanged method.
INotifyPropertyChanged interface just notifies the UI when an individual property is changed. This is currently the standard method for property change notification.
Another option you have is to create an object that has Dependency Properties. These have all the plumbing built in for change notification.
Have a look at my article:
http://www.codeproject.com/KB/WPF/WPFBusinessAppsPartThree.aspx[^]
Go look how I did the time display control. It also has a read only property that changes every 60 seconds and notifies the UI.
There are plenty of articles here on Code Project on writing your own Dependency Properties if you want to go that route.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
OK, thanks. I'll give that sample a look and read up more about dependency properties.
|
|
|
|
|
artwallacex wrote: Are there any solutions to just hardcoding a bunch of these NotifyPropertyChanged in every editable field?
Since you're using WPF then you'll be using C# 2.0 at least so you could do something like this (just made up an example since I haven't downloaded your files):
private TimeSpan _TimeCode;
private TimeSpan _TimeCodeCalc;
public TimeSpan TimeCode
{
get { return _TimeCode; }
set
{
_TimeCode = value;
TimeCodeCalc = new TimeSpan(value.TotalMinutes);
NotifyPropertyChanged("TimeCode");
}
}
public TimeSpan TimeCodeCalc
{
get { return _TimeCodeCalc; }
private set
{
_TimeCodeCalc = value;
NotifyPropertyChanged("TimeCodeCalc");
}
} You'll notice the private modifier on the TimeCodeCalc property, what this does is that only your class will be able to change the value. If you wrap your readonly properties like this then at least when you modify them you only have to set the wrapper property and the PropertyChanged event will be fired off. That way you don't have to remember to fire notify about every property in every place where you set it. Just use the new private set method rather than the field to modify the value.
[edit]
I've had a look at your simple solution and modified it to give you an example: http://www.pooredesign.com/downloads/wpf-databinding-calcupdate.zip[^]
[/edit]
|
|
|
|
|
Karl, I have another question now.
Based on editing one subitem, I need to change a value in another subitem. The change is working but the other subitem is not reflecting it's new value in the list.
I've implemented INotifyPropertyChanged on both the Item and Subitem classes but am unsure how to tell Wpf that other items in the list need to updated.
Nevermind, I think I've found the problem. I really need to get into those dependency properties because this INotifyPropertyChanged is turning into spaghetti.
modified on Thursday, May 1, 2008 6:12 PM
|
|
|
|
|
artwallacex wrote: this INotifyPropertyChanged is turning into spaghetti
INotifyProperyChanged should not be causing you too much grief. This is a very standard interface used by most WPF business objects that are bound to the UI.
If I could offer a suggestion? This is what I do when things get out of hand.
Write a very simple version of what you are trying to accomplish and work it piece by piece. The answer will come. If it doesn't, then you have a very simple project that anyone can look at and provide assistance. Trust me, I've been there.
Have a super day!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi Friends,
I am very new to WPF and Expression Blend.I am trying to learn .But i am being confused how to start and how to work on it.Can u please suggest me any sample applications,tutorials,pdfs or videos.but dont suggest "google" and tell me the which book is good for it?
Thank You very much in advance
|
|
|
|
|
|
kishorekumar.malla@live.com wrote: but dont suggest "google"
Why not? It's often a useful answer (especially if provided with a link). Have you searched this forum? I've provided links to video training for Blend in this forum before - you might want to take a look here[^].
|
|
|
|
|
|
Karl Shifflett wrote: I used the below site when I first wanted to learn Blend.
Same here. I couldn't have picked Blend up without it.
|
|
|
|
|
Another source you might find interesting -
Matthew MacDonald's book "Pro WPF in C# 2008 Windows Presentation Foundation with .NET 3.5 SECOND EDITION" Apress.
modified 1-Aug-19 21:02pm.
|
|
|
|
|
You're the second person who's recommended this book to me (Sacha being the first). I've only really looked at the Adam Nathan book and the Chris Sells book. I'll have to look into it.
|
|
|
|
|
Matthew MacDonald's books are SUPER and maybe the best WPF books in print.
I grew by leaps and bounds!
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Cool. I've just ordered my copy.
|
|
|
|
|
Trust your order for the book did not cost more than £23.16 including free worldwide delivery?
modified 1-Aug-19 21:02pm.
|
|
|
|
|
|
Compman's prices are better than my usual supplier [^]. Think I will change supplier in future.
modified 1-Aug-19 21:02pm.
|
|
|
|
|
And Me!!
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi, I'm using C# in a WPF Project and I need a TextBlock of Label that scrolls text from RightToLeft.
I can't find a decent example or explaining on the internet. I have found an example that uses SubString but this doesn't give a smooth animation. I think WPF can do better.
I need this in C# code not XAML.
Hope some one can help me.
Thanks.
Kevin
|
|
|
|
|