我正在使用Callburn.Micro for MVVM用C#WPF做一个简单的应用程序
我想执行ItemsControl
项的函数,但在单击Rectangle
项时出现下一个异常
System.Exception:"未找到方法
ChangeColor
的目标."
以下是XAML代码
<ItemsControl ItemsSource="{Binding Lines}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Background="LightYellow" Margin="10 0" Width="{Binding CanvasWidth}" Height="{Binding CanvasHeight}" Focusable="True"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding X}"/>
<Setter Property="Canvas.Top" Value="{Binding Y}"/>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Width="{Binding Width}"
Height="{Binding Height}"
Stroke="Black" StrokeThickness="1"
Fill="Black"
cal:Message.Attach="[Event MouseDown] = [Action ChangeColor()]"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
ItemsSource
是一个ObservableCollection
,它包含我创建的一个对象,该对象只有几个变量,如Rectangle
元素中的界限和ChangeColor
函数
我认为这与当前上下文有关,但我不明白为什么,当绑定变量Width
和Height
工作得很好时,尽管它们与ChangeColor
函数在同一个对象中