How can I check the F # / Silverlight field with the following code?

I would like to use the built-in Silverlight 4.0 field check in the following code, and I am having trouble working with it.

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 tried putting annotations over the myTextBox field in the .fs file, but the compiler complained about it (annotations like :) [Required(ErrorMessage="enter something!")].

Any ideas? Thank.

+3
source share
1 answer

I think you're lucky with this property, for example.

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 the Silverlight data well enough to check it out right now.

+2
source

Source: https://habr.com/ru/post/1778380/


All Articles