Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7841289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:04:09+00:00 2026-06-02T16:04:09+00:00

I’ve been looking for hours but I can’t find anything useful. Any help appreciated!

  • 0

I’ve been looking for hours but I can’t find anything useful. Any help appreciated!

I’m writing a Kinect application using WPF with the Coding4Fun toolkit and the MVVM pattern.

I’d like to put all my kinect related logic in my ViewModel and bind those methods to a HoverButton (found in the C4F toolkit).
A normal button had the ‘Command’ property, However the HoverButton does not.

So in short:

I want to bind the click event of a HoverButton to a method in my ViewModel.

My XAML:

<Window x:Class="KinectTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:fun="clr-namespace:Coding4Fun.Kinect.Wpf.Controls;assembly=Coding4Fun.Kinect.Wpf" Title="MainWindow" Height="350" Width="525"
    Loaded="WindowLoaded"
    Closed="WindowClosed"
    Cursor="None"
    >
<Grid Name="MainGrid" MouseMove="GridHoverMouseMove" DataContext="_viewModel">

    <Canvas Name="SkeletonCanvas" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="Black">
        <fun:HoverButton Name="KinectUp" ImageSource="/Images/blue_glass.png" ActiveImageSource="/Images/blue_glass.png" ImageSize="100" Canvas.Top="26" TimeInterval="1000">

        </fun:HoverButton>
        <fun:HoverButton Name="KinectDown" ImageSource="/Images/red_glass.png" ActiveImageSource="/Images/red_glass.png" ImageSize="100" Canvas.Bottom="26" TimeInterval="1000"/>

    </Canvas>
    <Image Name="ColorImage" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="120" Height="120"></Image>
            <TextBlock Name="Notification" Foreground="White" FontSize="50" VerticalAlignment="Top" HorizontalAlignment="Stretch" TextAlignment="Center" Text="{Binding Path=Notification, Mode=TwoWay}"></TextBlock>
    <Canvas Name="CanvMouse" Background="Transparent" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
        <Image Name="imgMouse" Width="70" Source="/Images/handround_green.png"></Image>
    </Canvas>
</Grid>
</Window>

My ViewModel:

internal class MainViewModel : INotifyPropertyChanged
{

    public event PropertyChangedEventHandler PropertyChanged;
    public ICommand KinectUpClick { get; private set; }
    public ICommand KinectDownClick { get; private set; }

    private string _notification = "Hello";
    public SensorHelper SensorHelper { get; set; }

    public string Notification
    {
        get { return _notification; }
        set
        {
            _notification = value;
            PropertyChanged(this, new PropertyChangedEventArgs("Notification"));
        }
    }



    public MainViewModel()
    {
        KinectUpClick = new RelayCommand(PerformKinectUpClick, CanKinectUpClick);
        KinectDownClick = new RelayCommand(PerformKinectDownClick, CanKinectDownClick);

    }

    private bool CanKinectUpClick(object parameter)
    {
        return SensorHelper.CanMoveUp;
    }

    private bool CanKinectDownClick(object parameter)
    {
        return SensorHelper.CanMoveDown;
    }

    private void PerformKinectUpClick(object parameter)
    {

        ThreadPool.QueueUserWorkItem((o) =>
        {
            Notification = "Kinect goes up!";
            SensorHelper.MoveAngle(5);
            Notification = "Kinect ready...";
        });
    }

    private void PerformKinectDownClick(object parameter)
    {
        ThreadPool.QueueUserWorkItem((o) =>
        {
            Notification = "Kinect goes down!";
            SensorHelper.MoveAngle(-5);
            Notification = "Kinect ready...";
        });
        ;
    }
}
}

My Code-behind:

public partial class MainWindow : Window
{
    private readonly MainViewModel _viewModel;
    private SensorHelper _sensorHelper;

    public MainWindow()
    {
        InitializeComponent();
        _viewModel = new MainViewModel();
        MainGrid.DataContext = _viewModel;
    }

    private void WindowLoaded(object sender, RoutedEventArgs e)
    {
        try
        {
            _sensorHelper = new SensorHelper();
        }
        catch (Exception exception)
        {
            MessageBox.Show(exception.Message);
        }
        _viewModel.SensorHelper = _sensorHelper;
        _sensorHelper.InitializeSkeleton(ref SkeletonCanvas);
        //_sensorHelper.CaptureMouse(CanvMouse);
        _sensorHelper.InitializeColorFrame(ColorImage);
        _sensorHelper.StartKinect();
    }



    private void WindowClosed(object sender, EventArgs eventArgs)
    {
        _sensorHelper.StopKinect();
    }

    private void GridHoverMouseMove(object sender, MouseEventArgs e)
    {
        imgMouse.SetValue(Canvas.LeftProperty, e.GetPosition(CanvMouse).X - imgMouse.ActualWidth/2);
        imgMouse.SetValue(Canvas.TopProperty, e.GetPosition(CanvMouse).Y - imgMouse.ActualHeight/2);

        MouseHelper.CheckButton(KinectUp, imgMouse);
        MouseHelper.CheckButton(KinectDown, imgMouse);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T16:04:10+00:00Added an answer on June 2, 2026 at 4:04 pm

    Okay, very simple, what you’ll have to do is bind an ICommand/Command to an Event by using an EventToCommand which can be found in the MVVMLight Toolkit.

    You can use Blend for that as well

    Simple example :

    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
        x:Class="TestProject.Window5"
        x:Name="Window"
        Title="Window5"
        Width="640" Height="480">
    
        <Grid x:Name="LayoutRoot">
            <Button Content="Button" HorizontalAlignment="Left" Height="69" Margin="92,117,0,0" VerticalAlignment="Top" Width="206">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding Kinect.MyCommand, Source={StaticResource Locator}}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.