f# - LiveCharts LabelFormatter 的 Elmish.Wpf 绑定(bind)

标签 f# livecharts elmish-wpf

我正在尝试将 LiveCharts 示例转换为 Basic Line Chart与 Elmish.Wpf 一起使用

除了“YFormatter”之外,我对所有东西都有绑定(bind)。我应该使用哪种绑定(bind)?

type Model = {
   AllSeries: SeriesCollection
   Labels: string[]
   Formatter: ???
}

let init() = (
    AllSeries = 
       let series = new SeriesCollection()
       series.Add(new LineSeries(Title="S1", Values=new ChartVAlues<int>(seq {4; 6; 5})))
       series
    Labels = [| "Jan"; "Feb"; "Mar" |]
    Formatter = ???
}

let bindings () : Binding<Model, MessageType> list = [
    "AllSeries" |> Binding.oneWay(fun m -> m.AllSeries)
    "Labels" |> Binding.oneWay(fun m-> m.Labels)
    "YFormatter" |> ?????
]

xaml 按照基本折线图示例

<lvc:CartesianChart Series="{Binding AllSeries}">
    <lvc:CartesianChart.AxisY>
        <lvc:Axis Title="Sales" LabelFormatter="{Binding YFormatter}"></lvc:Axis>
    </lvc:CartesianChart.AxisY>
    <lvc:CartesianChart.AxisX>
        <lvc:Axis Title="Month" Labels="{Binding Labels}"></lvc:Axis>
     </lvc:CartesianChart.AxisX>
</lvc:CartesianChart>

最佳答案

成功了

模型根本不需要“格式化程序”

所以,init 无关

绑定(bind)有

"YFormatter" |> Binding.oneWay(fun m -> Func<Double,_> (fun d -> d.ToString("C")))

关于f# - LiveCharts LabelFormatter 的 Elmish.Wpf 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67053789/

相关文章:

f# - 使用 Elmish.WPF (F#) 管理 WPF 选项卡控件?

asynchronous - 从异步函数内部更改 Elmish.WPF 模型

f# - 如何使用 Elmish.wpf 和 F# 管理多个窗口、用户控件和自定义控件?

performance - 为什么 Seq 模块中的某些功能得到了优化,而其他功能却没有在 F# 中进行优化?

f# - 为什么 F# 中的幂运算符仅适用于 float ?

c# - 无法将类型为 'System.DateTime' 的对象转换为类型 'System.String'。 C#

c# - 对齐两个具有不同轴标签宽度的笛卡尔图表?

visual-studio - Visual Studio 2010 智能感知 : hints on F# operators

c# - 设计或代码模式以从函数返回多个可选值

c# - 保存实时图表图像