<InkCanvas x:Name="inkCanv" Margin="10" Background="White" StrokeCollected="{Binding OnSaveInkStroke}" StrokeErased="{Binding OnSaveInkStroke}" StrokeErasing="{Binding OnSaveInkStroke}">
            </InkCanvas>
        public ICommand OnSaveInkStroke { get; set; }
        public void SaveInkStroke()
        {        }以上绑定在运行时报错:
{"无法将类型为“System.Reflection.RuntimeEventInfo”的对象强制转换为类型“System.Reflection.MethodInfo”。"}谢谢

解决方案 »

  1.   

    这个和上一个帖子是同样的问题,事件不能绑定。要么用事件触发器去InvokeCommandAction,要么在code behind类里写事件处理方法。
    如果你要用inline的附加属性方法的话,在前一贴的基础上再加上下面这些类定义: public class StrokeCollected : EventCommand<StrokeCollected> { static StrokeCollected() { Register(InkCanvas.StrokeCollectedEvent); } }
    public class StrokeErased : EventCommand<StrokeErased> { static StrokeErased() { Register(InkCanvas.StrokeErasedEvent); } }
    public class StrokeErasing : EventCommand<StrokeErasing> {
    static StrokeErasing() { Register<InkCanvas>(x=>x.StrokeErasing+=InvokeCommand, x=>x.StrokeErasing-=InvokeCommand); }
    }前台改成:    <InkCanvas x:Name="inkCanv" Margin="10" Background="White"
                    local:StrokeCollected.Command="{Binding OnSaveInkStroke}" 
                    local:StrokeErased.Command="{Binding OnSaveInkStroke}" 
                    local:StrokeErasing.Command="{Binding OnSaveInkStroke}">
        </InkCanvas>