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.
I think you'll have better luck with a property, eg
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.