问题描述
我是Elmish的新手。
WPF绑定使用以下自定义控件:
local:AppointmentListView.ScheduledAppointment ="AppointmentDataGrid_ScheduledAppointment"
我有提高当选择了列表视图项以下的路由事件C#定制的ListView:
private void AppointmentListView_PreviewMouseLeftButtonUp(object sender,MouseButtonEventArgs e)
{
var item = (sender as ListView).SelectedItem;
if ((IVisit)item != null)
{
ScheduledAppointmentEventArgs args = new ScheduledAppointmentEventArgs(ScheduledAppointmentEvent,(IVisit)item);
RaiseEvent(args);
}
}
我不需要C#强制转换为“ IVisit”,但是我确实需要从F#模型中将选定的列表视图项设置为“访问”类型。也就是说,我需要实际的对象约会键。但是我得到的是: “ Elmish.WPF.viewmodel ”
在Elmish.WPF中,ListView的itemsSource被定义为“ AppointmentKeys”,
type Model =
{ AppointmentKeys: Visit.Model list
Id: int
}
let bindings() =[
"AppointmentKeys" |> Binding.subModelSeq(
(fun (_,m) -> m.AppointmentKeys),(fun v -> v.Id),Visit.bindings
)
因此,问题是:在后面的代码中,如何返回用户从ListView中选择的F#记录?
更具体地说,当“ SelectedItem”来自MouseButtonEvents上的代码隐藏绑定时,如何编写F#代码以返回选定的列表视图项?
解决方法
不要使用您的后台代码中定义的函数订阅事件。而是将事件从like this转换为命令EventBindingsAndBehaviors
sample。然后像在SubModelSelectedItem
sample中一样,绑定到ListView
中的选定项目。