我有一个UserControl,默认的一个由VS生成,只添加了TextBlock:

<UserControl x:Class="MyNameSpace.Presentation.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="myControl">
    <Grid>
        <TextBlock x:Name="SomeTextBox" Text="SomeText"></TextBlock>
    </Grid>

现在,我将这个控件的几个实例从后面的代码中动态地放入父控件的WrapPanel中。我想处理来自MyControl实例的所有鼠标左键单击。我有以下代码:

<UserControl x:Class="Minimo.Presentation.FirstParent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Presentation="clr-namespace:Minimo.Presentation"
Height="300" Width="300">
<WrapPanel Name="wrapPanelOfMyControls" MyControl.MouseLeftButtonDown="WrapPanel1_OnMouseLeftButtonDown">
</WrapPanel>

在事件处理程序中我做了一些动作,并且它有效。但是,编辑XAML文件时出现以下错误: 在'MyControl'类型中找不到可附加属性'MouseLeftButtonDown'。如何解决这个问题?

有帮助吗?

解决方案

这只是XAML编译器/设计器的一个错误,可以安全地忽略。但是,您可能能够“修复”通过指定一种更密切注意的类型:

UIElement.MouseLeftButtonDown="WrapPanel1_OnMouseLeftButtonDown"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top