2

Here is what I have done using 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 

and in xaml

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

How can I use command dependecy of ViewModule to set x.ListOfData instead of calling returnPrice(value) in setter of x.SelectedId?

4

1 回答 1

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() 的目的是什么以及如何使用它?

于 2016-11-23T04:53:02.370 回答