views:

42

answers:

2

I have code like this, in pagefunction making up a wizard:

<TextBox Name="txtDate" Text="{Binding Path=Date}"></TextBox>

The user types in and clicks next, object sent to next page with this data.

But if I set

<TextBox Name="txtDate" Text="{Binding Path=Date, TargetNullValue='2010-01-15'}"></TextBox>

So I can have some "example" text in the box already, and the user hits next to accept this without changing it, no value is passed in the object to the next pagefunction. If the user changes it then it works as usual.

So how can I have some default text without stopping the data being sent on?

+1  A: 

You could set an initial value on the date that you are binding to.

If the Date property is a dependency property when you create it you can give it an inital value. Then you could attach a handler to notify you when it changed, and mark a flag as non intial value. (so you know its changed)

Aran Mulholland
So if this is from a class of like Person and say the date is DateBorn attribute, I set default value in the class to that date?
baron
yep thats the go. you could set it to DateTime.MinValue (1/1/0001)
Aran Mulholland
+1  A: 

If you're providing a true data default (i.e. one that is a valid data value) consider initializing your data-bound object to that value.

micahtan