【发布时间】:2016-05-05 12:10:53
【问题描述】:
我有以下错误:
Windows.UI.Xml.Controls.ListView 类型的对象无法转换为 System.Windows.DependencyObject 类型
由于以下代码:
<ListView Grid.Row="1" ItemsSource="{Binding Cases}" IsItemClickEnabled="False" SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Subject}" HorizontalAlignment="Left"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding ShowCaseCommand, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListView>
我将 EventTrigger 添加到命名空间中,如下所示:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
我通过手动添加来自C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.5\Libraries\System.Windows.Interactivity.dll 的引用将交互添加到项目中。
当然,删除 <i:Interaction.Triggers> 块可以消除错误,但我需要将选择绑定到命令,就像我在 UIKit 和 Android 中所做的那样。
那么——这是什么魔鬼?
【问题讨论】:
-
为什么不能将 SelectedItem 绑定到 ViewModel 中的属性?
-
如果我有一个 setter 调用 ShowViewModel 比 ViewModel 的界面不太直观。似乎 Daily Dilbert 示例在 iOS 中使用 ItemSelectedCommand 而不是 Windows Store。如果我弄清楚为什么触发器不起作用,我会在这里发布答案,但我可能会以某种方式结束核心库。
标签: windows xaml windows-runtime mvvmcross