|
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
|
|
|
|
|
|
Remember, anything done in XAML can be done in code.
I'll have to disagree with you on that one.
Example try to Underline a Label.
In Xaml you can do,
< label >
< underline >
Some Text
< \underline >
< \label >
Try to do that in code. I coudn't find it.
I still didn't got it to work by the way. I must say I am only programming for half a year.
I don't know how to do some things in the example in C# code.
modified on Tuesday, April 29, 2008 9:46 AM
|
|
|
|
|
KBou wrote: I'll have to disagree with you on that one.
Everything done in XAML can be done in code. All XAML gets compiled into code.
Notice in the below example, the code just creates the same classes that the XAML does.
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel x:Name="LayoutRoot">
<Label>
<Underline>Some Text</Underline>
</Label>
</StackPanel>
</Window>
Class Window1
Private Sub Window1_Loaded(ByVal sender As Object, _
ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim lbl As New Label
Dim und As New Underline
und.Inlines.Add("Hi from Code!")
lbl.Content = und
Me.LayoutRoot.Children.Add(lbl)
End Sub
End Class
modified 27-Feb-21 21:01pm.
|
|
|
|
|
I'll take it back.
Everything done in XAML can be done in code.
But I would still like some help with an example in code because I can't get it to work propperly.
Thanks for the Underline anyway
|
|
|
|
|
What exactly does not work?
Here is a link to a super book on writing WPF Code. This is the link to the Source Code download that has lots of animiation code.
http://www.microsoft.com/mspress/companion/0-7356-1957-3/[^]
From what you wrote before, you want to scroll text.
One way to accomplish this, is to us an animation and a TranslateTransform to change the position of the text.
If you are on a canvas, you can animate the x & y points.
You down load Express Blend 2.5 Preview for free. You can write and study doing this in a few minutes in Blend.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Well I kinda got it to scroll the way I want.
But...
Here's the situation.
I've got an UserControl that can contains a TextBlock.
The text in the TextBlock should scroll from left to right,
But the text shoudn't be visible when it's outside of the UserControl.
This is what I have got so far.
TextBlock tb = (TextBlock)this.Content;
tb.FlowDirection = FlowDirection.LeftToRight;
DoubleAnimation Animation = new DoubleAnimation();
Animation.From = this.Width;
Animation.To = -tb.DesiredSize.Width;
Animation.Duration = new Duration(TimeSpan.FromSeconds(10));
TranslateTransform tt = new TranslateTransform();
tt.BeginAnimation(TranslateTransform.XProperty, Animation);
tb.RenderTransform = tt;
Any ideas how I can get the visibility part? And how do I use a storyboard in this for Repeating?
|
|
|
|
|
KBou wrote: Any ideas how I can get the visibility part?
Read up on the "ClipToBounds" property and set this on your UserControl. I'll assume that you have set a specific height and width on your UserControl.
You should add a method to your UserControl so that the parent container can all the UserControl to start and/or stop the animation. A property for the TextBlock.Text is also in order unless the text is always the same.
KBou wrote: And how do I use a storyboard in this for Repeating?
What are you trying to do?
Have the animation keep repeating?
Have the animation repeat on command? If so, is this command executed in code or XAML?
You used the word storyboard, why? From the beginning you wanted a code only solution, what was the reason for a code only solution instead of using a XAML storyboard?
modified 27-Feb-21 21:01pm.
|
|
|
|