问题描述
|
我一直在学习Silverlight中的MVVM模式,并想知道当ViewModel构造函数具有接口类型的参数时,如何实现从View到ViewModel的绑定。
如果我将viewmodel绑定到XAML中的视图,则不能使用参数化的构造函数。鉴于我正在创建一个默认的构造函数,将实例传递给参数化的构造函数,但这破坏了抽象。
视图
<navigation:Page x:Class=\"QSmart.DataViewer.Report.RecentFailures.Report\"
xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"
xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"
xmlns:d=\"http://schemas.microsoft.com/expression/blend/2008\"
xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"
mc:Ignorable=\"d\"
xmlns:navigation=\"clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation\"
xmlns:local=\"clr-namespace:QSmart.DataViewer.Report.RecentFailures\"
d:DesignWidth=\"640\" d:DesignHeight=\"480\"
Title=\"Report Page\" xmlns:telerik=\"http://schemas.telerik.com/2008/xaml/presentation\">
<UserControl.Resources>
<local:ReportViewModel x:Key=\"ViewModel\"/>
</UserControl.Resources>
<Grid x:Name=\"LayoutRoot\" DataContext=\"{StaticResource ViewModel}\" >
<telerik:RadGridView Name=\"RadGridView1\" ItemsSource=\"{Binding Path=Faults,Mode=OneWay}\" AutoGenerateColumns=\"True\" />
</Grid>
</navigation:Page>
查看模型
Public Sub New(ByVal serviceDataAgent As IRecentFailuresReportServiceAgent)
If Not IsInDesignMode Then
If serviceDataAgent IsNot Nothing Then
ServiceAgent = serviceDataAgent
End If
Messenger.Default.Register(Of RecentFailuresMessage)(Me,Sub(m) ChangeReportSettings(m))
LoadData()
End If
End Sub
解决该问题的方法是什么?是否建议使用视图后面的代码传递给参数化构造函数,然后绑定到视图模型?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)