开发者

Event handling for bound canvas WPF

I have a number of canvas bound to an observable collection. Each of which itself is bound to an observable collection of objects (Binding-a-nested-list-to-a-wpf-canvas-panel).

My problem is that I cant seem to add event handlers to those canvas. I tried adding a PreviewMouseLeftButt开发者_Go百科onDown event to both, the Canvas and the ItemControl, but both give a null reference exception even if the event is empty and I havent clicked the canvas.

Does this happen for a reason? Is there a way around it?

Thanks.


Can you try this code?

<Grid PreviewMouseDown="Grid_PreviewMouseDown">
            <Border Padding="5" BorderThickness="1" BorderBrush="Red" CornerRadius="3"
                                Background="White">
                <TextBlock Text="{Binding Name}" />
                        </Border>
        </Grid>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜