How can I do F#/Silverlight field validation with the following code?
I'd like to use the built-in Silverlight 4.0 field validation on the following code, and am having trouble getting it to work.
MyForm.fs:
// imports, etc
type MyForm() as this =
inherit UriCanvasControl("/Project;component/MyForm.xaml", "Enter Stuff")
[<DefaultValue>]
val mutable myTextBox: TextBox
do
Application.LoadComponent(this, base.uri)
this.myTextBox <- this?myTextBox
// other stu开发者_如何学Pythonff
MyForm.xaml:
// ...
<TextBox Name="myTextBox" Text="{Binding Path=myTextBox,Mode=TwoWay,ValidatesOnExceptions=True,NotifyOnValidationError=True}" TextChanged="Duration_Changed" Grid.Column="0" Margin="0,0,2,0"></TextBox>
// ...
I've tried putting annotations above the myTextBox field in the .fs file, but the compiler complained about that (annotations like: [Required(ErrorMessage="enter something!")]
).
Any ideas? Thanks.
I think you'll have better luck with a property, e.g.
type Yadda() = ...
let mutable backingField : TextBox = null
[<RequiredOrWhatever(blah)>]
member this.TheProperty with get() = backingField
and set(x) = backingField <- x
but I don't know Silverlight details well enough to verify it right now.
精彩评论