Topic Author
Posts: 5
Joined: 21 Aug 2018, 01:30

Binding to Thumb.DragStarted event in Unity + NoesisGUI

01 Sep 2018, 04:03

Hey, we are trying to bind to the Thumb.DragStarted event so we can know when the user starts dragging a slider. Here’s our XAML and Code Behind:

<Slider  Thumb.DragStarted="Slider_DragStarted"  Width="200" VerticalAlignment="Center" Maximum="100" SmallChange="1" LargeChange="10" Value="{Binding SliderValue}" Margin="187.5,13.011,412.5,418.989"/>
Code Behind:
private void Slider_DragStarted(object sender, System.Windows.Controls.Primitives.DragStartedEventArgs e)
            // Debug.Log("Drag started");
This code runs in a pure C# WPF app. But when we run in Unity using NoesisGUI, we get the following error:
The type or namespace name `Controls' does not exist in the namespace` System.Windows'. Are you missing an assembly reference?
We are able to avoid this error by changing the Slider_DragStarted method to:
private void Slider_DragStarted(object sender, object e)

  // Debug.Log("Drag started");

However, this then results in the following new error:
NoesisException: Assets/UI/PlayerControls.xaml(11): 'KMotionMVVM.PlayerControls' does not contain a definition for 'Slider_DragStarted’
Do you have any recommendations on what we might be doing wrong here?

User avatar
Site Admin
Posts: 2331
Joined: 22 Dec 2011, 19:20

Re: Binding to Thumb.DragStarted event in Unity + NoesisGUI

05 Sep 2018, 10:49


With current C# API is not possible yet to register against attached events because RoutedEvents are not exposed neither are UIElement.AddHandler/RemoveHandler.
Could you please add a request in our bugtracker for this?

The option you have now is to assign a name to the Slider and in your user control's Loaded event search for the slider's Thumb (inside the template).
public MyUserControl()
  Loaded += OnLoaded;

void OnLoaded()
  Slider slider = (Slider)FindName("Slider");
  Thumb thumb = (Thumb)slider.GetTemplateChild("SliderThumb");
  thumb.DragStarted += Slider_DragStarted;
Sorry for the inconveniences.

Who is online

Users browsing this forum: Logrus and 3 guests