我有一个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’。如何解决这个问题?
发布于 2009-06-22 07:23:22
这只是XAML编译器/设计器的一个bug,可以安全地忽略。但是,您可以通过指定它更熟悉的类型来“修复”它:
UIElement.MouseLeftButtonDown="WrapPanel1_OnMouseLeftButtonDown"https://stackoverflow.com/questions/1025749
复制相似问题