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?

FoggyFinder
  • 2,230
  • 2
  • 20
  • 34

1 Answers1

3

You assumed it right @Foggy Finder. I have replaced the code to -

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)

and it works!

What is the purpose of self.DependencyTracker.AddCommandDependency() and How to use it?

  • 1
    never used this function. But the purpose is clear from the name. – FoggyFinder Nov 23 '16 at 09:56
  • 1
    That kind of belongs in a separate question - but in general, it's something you don't (normally) need to use yourself. It works like the property depednencies, but for teh canexecute of a command. Normally, when you create the command, you just include it in the dependent expressions, and the framework wires that up for you. – Reed Copsey Nov 23 '16 at 20:47
  • Thanks @ReedCopsey for your comment. Can you please suggest me some site/blog/video link as starter's guide to get idea about developing ASP.NET MVC application using F#? –  Nov 24 '16 at 05:36
  • @emonhaque I'd recommend joining the F# software foundation, and asking in the Web channel of their slack team... likely will get the best answer. – Reed Copsey Nov 24 '16 at 05:38
  • @ReedCopsey Thanks once again. FsMvc5 is the right one for me. –  Nov 24 '16 at 07:16