如何使用FsXaml的CommandDependecy /(ies)

时间:2016-11-22 20:12:12

标签: wpf f# fsxaml fsharp.viewmodule

以下是我使用FsXaml

所做的事情
type MainViewModel() as self = 
inherit ViewModelBase() 

    let listOfData = self.Factory.Backing(<@self.ListOfData@>, 0 :> obj)
    let selectedId = self.Factory.Backing(<@self.SelectedId@>, 0)

    member x.SelectedId with get() = selectedId.Value 
                        and set value = selectedId.Value <- value;
                                        x.ListOfData <- returnPrice(value) :> obj        
    member x.StockList with get() = stockList
    member x.ListOfData with get() = listOfData.Value and set value = listOfData.Value <- value 

和xaml

<ComboBox Grid.Row="1" ItemsSource="{Binding StockList}" 
              DisplayMemberPath="Code" 
              SelectedValuePath="Id" SelectedValue="{Binding SelectedId}"/>
<DataGrid Grid.Row="2" ItemsSource="{Binding ListOfData}"/>

如何使用ViewModule的命令依赖来设置x.ListOfData,而不是在returnPrice(value)的设置者中调用x.SelectedId

1 个答案:

答案 0 :(得分:3)

你认为它正确@Foggy Finder。我已将代码替换为 -

let selectedId = self.Factory.Backing(<@self.SelectedId@>, 0)  

do
    self.DependencyTracker.AddPropertyDependency(<@self.ListOfData@>,<@self.SelectedId@>)

member x.SelectedId with get() = selectedId.Value and set value = selectedId.Value <- value;
member x.StockList with get() = stockList
member x.ListOfData with get() = returnPrice(self.SelectedId)

它有效!

self.DependencyTracker.AddCommandDependency()的目的是什么以及如何使用它?