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 stuff

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.

Answers


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.


Need Your Help

CodeFile vs CodeBehind

asp.net

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?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.