gpt4 book ai didi

wpf - 如何将命令/属性绑定(bind)到 FSharp.ViewModule 中的 PropertyChanged

转载 作者:行者123 更新时间:2023-12-03 10:16:06 24 4
gpt4 key购买 nike

FSarp.ViewModule我有一个简单的 View ,单击按钮会根据右侧的文本框在左侧的文本框中生成一个随机数。如何绑定(bind)右侧文本框中的更改(例如手动输入数字),以便通过调用 clickcommand 或 click() 方法而不单击按钮来更新左侧文本框?我尝试了 self.DependencyTracker 的不同组合和 self.RaisePropertyChanged但无法正确使用语法。

这是 View :

View

XAML:

<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Height="55" Margin="130,55,0,0" VerticalAlignment="Top" Width="115" Command="{Binding Click}"/>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="50" Margin="30,55,0,0" TextWrapping="Wrap" Text="{Binding Data, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="70"/>
<TextBox x:Name="textBox2" HorizontalAlignment="Left" Height="50" Margin="280,55,0,0" TextWrapping="Wrap" Text="{Binding Data2, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Top" Width="70"/>

和 View 模型:
type RandomX = {
DataOut: int
DataIn: int
}

type MainRandomModel(model:RandomX) as self =
inherit ViewModelBase()
let rnd = System.Random()

let defaultNums = model //{DataOut = 100; DataIn = 100}

let data = self.Factory.Backing(<@ self.Data @>, defaultNums.DataOut )
let data2 = self.Factory.Backing(<@ self.Data2 @>, defaultNums.DataIn)
let click() = data.Value <- rnd.Next(data2.Value)
let clickcommand = self.Factory.CommandSync(click)
member self.Click = clickcommand
member self.Data with get() = data.Value and set v = data.Value <- v
member self.Data2 with get() = data2.Value and set v = data2.Value <-v

new() = MainRandomModel({DataOut=20;DataIn=10})

最佳答案

您只需调用click Data2 的 setter 中的函数:

member self.Data2 with get() = data2.Value 
and set v = data2.Value <- v ; click()

关于wpf - 如何将命令/属性绑定(bind)到 FSharp.ViewModule 中的 PropertyChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37542681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com