Custom UserControl not working if inside CardControl

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 2 months ago by Marco Birkholz - Germany
Version: 24.1.4
Avatar

Hi Guys,

as a newbie by myself, a heavy question. Since I can not affort a license for my own, I only have some few moments where I have access to play around with these wonderful controls. I really like them and would love to use them furthermore.

But I had a very strange problem with my Custom-Control.
Putting a WPF-Button inside a Card-Control, works fine.
Putting a WPF-Button inside a User-Contol into a Card-Control, works fine.

Putting my Custom-Control inside a Card-Control does not work. My User-Control is visible, but does not react to anything at all. Mouse-Clicks are not passed to the codebehind. Outside a Card-Control, my Custom-Control worked fine.

I tried some few hours and found out, that there is something going on whith a MouseButtonUp-Event inside a Card-Control. This seems not to be fired if inside a Card-Control. The MouseButtonDown-Event works fine, even inside a Card-Control.

Am I doing something wrong, or is there a limitation (with actipro-controls) or rule or reason, I ran into? 

This is a simple Testcontrol, put it into a Card-Control and the click event is not fired anymore, but if you change it to "MouseLeftButtonDown", it will work:

<UserControl x:Class="libApplicationBase.Controls.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:libApplicationBase.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800" Height="40" Width="60">
    <Border Background="Green" MouseLeftButtonUp="Border_MouseLeftButtonUp">
            
    </Border>
</UserControl>
using System.Windows.Controls;
using System.Windows.Input;

namespace libApplicationBase.Controls
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        private void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {

        }
    }
}

With best regards

Marco

[Modified 2 months ago]

Comments (1)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Marco,

Our Card control derives from Button (since it is clickable), and the default behavior of Button will consume the mouse down/up events.  If you update the UserControl to listen to the MouseLeftButtonDown event (either via MouseLeftButtonDown or PreviewMouseLeftButtonDown) and mark MouseButtonEventArgs.Handled = true then your UserControl should receive the subsequent mouse events (like MouseLeftButtonUp) instead of allowing them to bubble up to the parent Card control.

private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
    e.Handled = true;
}


Actipro Software Support

The latest build of this product (v24.1.5) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.