Databinding - setting default value
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 obje开发者_运维问答ct 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?
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)
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.
精彩评论