I am trying to merge values from 5 textboxes in to a string to display in a label. However I am getting this error message
This expression was expected to have type string but here has type string -> string -> string -> string -> string
I can show the anyone textbox value into the label. Here is the code I as using:
let temp = self.Factory.Backing(<@ self.Temp @>, "")
let ph = self.Factory.Backing(<@ self.PH @>, "")
let soil = self.Factory.Backing(<@ self.SOIL @>, "")
let slope = self.Factory.Backing(<@ self.SLOPE @>, "")
let aspect = self.Factory.Backing(<@ self.ASPECT @>, "")
let display = self.Factory.Backing(<@ self.Display @>, "")
let goCommand = self.Factory.CommandSyncParam(fun param -> self.Display <- sprintf "The data that has been enter is:\n%s,\n %s,\n %s,\n %s,\n %s" param)
member x.TEMP with get() = temp.Value and set value = temp.Value <- value
member x.PH with get() = ph.Value and set value = ph.Value <- value
member x.SOIL with get() = soil.Value and set value = soil.Value <- value
member x.SLOPE with get() = slope.Value and set value = slope.Value <- value
member x.ASPECT with get() = aspect.Value and set value = aspect.Value <-value
member x.Display with get() = display.Value and set value = display.Value <- value
member x.GoCommand = goCommand
I found this code How do I concatenate a list of strings in F#? and this is what output that I want. So I tried the this code with with my values.
let strings =["temp.Value"; "ph.Value"; "soil.Value"]
let r = strings |> List.fold (fun r s -> r + s + "\n") ""
printfn "%s"
I got this as the output:
temp.Value
ph.Value
soil.Value
So how do you get the Value of each category to show up and how to merge it to the "let goCommand?"
edited per request to showing the xaml code
<TextBox Grid.Row="3" Grid.Column="1" FontSize="14" Text="{Binding TEMP}"/>
<TextBox Grid.Row="4" Grid.Column="1" FontSize="14" Text="{Binding PH}"/>
<TextBox Grid.Row="5" Grid.Column="1" FontSize="14" Text="{Binding SOIL}"/>
<TextBox Grid.Row="6" Grid.Column="1" FontSize="14" Text="{Binding SLOPE}"/>
<TextBox Grid.Row="7" Grid.Column="1" FontSize="14" Text="{Binding ASPECT}" Grid.ColumnSpan="3" Margin="0,0,16,0" />
<Button Margin="0,31,0,652" Grid.Row="8" FontSize="16" Content="Submit" Foreground="DarkBlue" FontWeight="Heavy" Background="LightBlue"
Command="{Binding GoCommand}" CommandParameter="{Binding TEMP, PH, SOIL,SLOPE, ASPECT}"/>
Your properties (x.TEMP,...) are available from the MainViewModel - you don't need to try to transfer their values as a parameter. So you need to use the command without any parameters:
.xaml:
<Button Margin="0,31,0,652" Grid.Row="8" FontSize="16"
Content="Submit" Foreground="DarkBlue" FontWeight="Heavy"
Background="LightBlue" Command="{Binding GoCommand}" />
.fs:
let display = self.Factory.Backing(<@ self.Display @>, "")
let go() =
self.Display <- sprintf "The data that has been enter is:\n%s,\n %s,\n %s,\n %s,\n %s"
self.TEMP self.PH self.SOIL self.SLOPE self.ASPECT
let goCommand = self.Factory.CommandSync(go)
Edit:
Full .fs:
type MainViewModel() as self =
inherit ViewModelBase()
let temp = self.Factory.Backing(<@ self.TEMP @>, "")
let ph = self.Factory.Backing(<@ self.PH @>, "")
let soil = self.Factory.Backing(<@ self.SOIL @>, "")
let slope = self.Factory.Backing(<@ self.SLOPE @>, "")
let aspect = self.Factory.Backing(<@ self.ASPECT @>, "")
let display = self.Factory.Backing(<@ self.Display @>, "")
let go() =
self.Display <- sprintf "The data that has been enter is:\n%s,\n %s,\n %s,\n %s,\n %s"
self.TEMP self.PH self.SOIL self.SLOPE self.ASPECT
let goCommand = self.Factory.CommandSync(go)
member x.TEMP with get() = temp.Value and set value = temp.Value <- value
member x.PH with get() = ph.Value and set value = ph.Value <- value
member x.SOIL with get() = soil.Value and set value = soil.Value <- value
member x.SLOPE with get() = slope.Value and set value = slope.Value <- value
member x.ASPECT with get() = aspect.Value and set value = aspect.Value <-value
member x.Display with get() = display.Value and set value = display.Value <- value
member x.GoCommand = goCommand