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.


// imports, etc
type MyForm() as this =
    inherit UriCanvasControl("/Project;component/MyForm.xaml", "Enter Stuff")

    val mutable myTextBox: TextBox

        Application.LoadComponent(this, base.uri)
        this.myTextBox <- this?myTextBox
// other stuff


// ...
<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
    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.

Need Your Help

CodeFile vs CodeBehind

What is the difference between CodeFile="file.ascx.cs" and CodeBehind="file.ascx.cs" in the declaration of a ASP.NET user control?

Getter property with arguments

c# properties

I guess I've seen somewhere before, but now I can't remember neither find it, is there a way to make a getter property with arguments?