【发布时间】:2015-04-30 12:06:54
【问题描述】:
我的项目控件中的 WPF 绑定有问题。出现以下错误
System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“RelativeSource”(HashCode=56697999)上找不到“MovieImageClick”属性。 BindingExpression:Path=MovieImageClick; DataItem='RelativeSource' (HashCode=56697999);目标元素是“EventToCommand”(HashCode=42916613);目标属性是“Command”(输入“ICommand”)
XAML 的一个简单示例:
<ItemsControl x:Name="movie_poster_grid" ItemsSource="{Binding Mode=TwoWay, Path=AllMovies}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageURL}" Stretch="UniformToFill" Width="200" Height="300">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDown">
<cmd:EventToCommand Command="{Binding MovieImageClick , RelativeSource={RelativeSource FindAncestor, AncestorType=ItemsControl}}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我有一个 MVVM 框架,并通过以下方式将数据上下文连接到 ModernUserControl:
DataContext="{Binding MovieListModel, Source={StaticResource Locator}}"
在这个视图模型内部是一个 Relaycommand MovieImageClick,我希望将触发器连接到。
情况: 如果我将触发器直接放在 itemscontrol 中,它将起作用!如果我将触发器更深地放在 itemscontrol 内部,它就不起作用。所以我认为问题在于在整个项目控制中找到视图模型。奇怪的是,触发器可以找到itemscontrol,但找不到命令什么的。请帮帮我!
【问题讨论】:
标签: wpf mvvm binding nested itemscontrol