Question

I have a UserControl, default one generated by VS, only TextBlock is added:

<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>

Now, I put several instances of this control into parent control's WrapPanel dynamically from the code behind. I want to handle all Left Mouse Button clicks from MyControl instances. I have following code:

<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>

In the event handler I make some action, and it works. However I get the following error when editing the XAML file: The attachable property 'MouseLeftButtonDown' was not found in type 'MyControl'. How to fix this?

Was it helpful?

Solution

This is just a bug with the XAML compiler/designer and can be safely ignored. However, you may be able to "fix" it by specifying a type it is more intimately aware of:

UIElement.MouseLeftButtonDown="WrapPanel1_OnMouseLeftButtonDown"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top