I have defined the following DataTemplate
for ListBox
items in an external resource dictionary:
Method 1:
Use your own control inherited from Slider
:
public class SpecialSlider : Slider
{
public SpecialSlider()
{
ValueChanged += OnValueChanged;
}
private void OnValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
// ...
}
}
Method 2: use behaviors from System.Windows.Interactivity.dll assembly (available through the NuGet):
public class SpecialSliderBehavior : Behavior
{
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.ValueChanged += OnValueChanged;
}
protected override void OnDetaching()
{
base.OnDetaching();
AssociatedObject.ValueChanged -= OnValueChanged;
}
private void OnValueChanged(object sender, RoutedPropertyChangedEventArgs e)
{
// ...
}
}
This is how to attach it:
...
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
...