0

我下载了一个 Github 项目,并在 VS 2012 中打开它后自动升级。我收到一个我不明白的错误。它与报价有关。

这是我复制粘贴在下面的文件:https ://github.com/dmitry-a-morozov/fsharp-wpf-mvc-series/blob/master/Chapter%2012%20-%20BindingMicroDSL/BindingMicroDSL/StockPricesChart.fs

错误是“引用可能不涉及分配或获取捕获的局部变量的地址”

有问题的代码是这个键和值:

this.Control.DetailsName, <@@ stockProperty.Key @@>

this.Control.DetailsValue, <@@ stockProperty.Value @@>

namespace FSharp.Windows.Sample

open System.Windows.Data
open System.Drawing
open System.Windows.Forms.DataVisualization.Charting
open System.Collections.ObjectModel

open FSharp.Windows
open FSharp.Windows.UIElements

[<AbstractClass>]
type StockPricesChartModel() = 
    inherit Model()

    abstract StocksInfo : ObservableCollection<StockInfoModel> with get, set
    abstract SelectedStock : StockInfoModel with get, set

type StockPricesChartView(control) as this =
    inherit PartialView<unit, StockPricesChartModel, StockPricesChartControl>(control)

    do 
        let area = new ChartArea() 
        area.AxisX.MajorGrid.LineColor <- Color.LightGray
        area.AxisY.MajorGrid.LineColor <- Color.LightGray        
        this.Control.StockPricesChart.ChartAreas.Add area
        let series = 
            new Series(
                ChartType = SeriesChartType.Column, 
                Palette = ChartColorPalette.EarthTones, 
                XValueMember = "Symbol", 
                YValueMembers = "LastPrice")
        this.Control.StockPricesChart.Series.Add series

    override this.EventStreams = 
        [
            this.Control.AddStock.Click |> Observable.mapTo()
        ]

    override this.SetBindings model = 
        this.Control.StockPricesChart.DataSource <- model.StocksInfo
        model.StocksInfo.CollectionChanged.Add(fun _ -> this.Control.StockPricesChart.DataBind())

        this.Control.Symbol.SetBindings(
            itemsSource = <@ model.StocksInfo @>, 
            selectedItem = <@ model.SelectedStock @>,
            displayMember = <@ fun m -> m.Symbol @> 
        )

        this.Control.Details.SetBindings(
            itemsSource = <@ model.SelectedStock.Details @>, 
//////////////////            OFFENDING CODE    ///////////////////
            columnBindings = fun stockProperty ->
                [
                    this.Control.DetailsName, <@@ stockProperty.Key @@>
                    this.Control.DetailsValue, <@@ stockProperty.Value @@>
                ]
        )

type StockPricesChartController() = 
    inherit Controller<unit, StockPricesChartModel>()

    override this.InitModel model = 
        model.StocksInfo <- ObservableCollection()

    override this.Dispatcher = fun() -> 
        Async <| fun model ->
            async {
                let! result = Mvc.startWindow(StockPickerView(), StockPickerController())  
                result |> Option.iter(fun newItem -> 
                    model.StocksInfo.Add newItem
                    model.SelectedStock <- newItem
                )
            }
4

1 回答 1

5

这是 F# 3.0 的重大变化 http://msdn.microsoft.com/en-us/library/hh416791.aspx 正如 Leaf Garland 指出的那样,这不是您问题的直接答案,但请查看升级到 VS 2012 代码https:// github.com/dmitry-a-morozov/fsharp-wpf-mvc-series/wiki/Visual-Studio-2012

于 2013-06-03T14:41:43.953 回答