I have created a reusable slider control using Syncfusion. I read from a database to show the "set", "target" and other values. The reusable control as increment/decrement buttons, a checkbox, and a save button on it. I'm running into trouble when I place multiple sliders. I have created a case statement to load the proper values for each slider, however, I don't know how I can determine which control's button has been clicked so I can increment/decrement/change checkbox/etc. of just that slider control that has been click.
Thank you in advance for taking the time to review my problem!
What I have tried:
Below is the generic slider user control:
<usercontrol x:class=" height="Auto" width="310">
Below is the placement of two controls onto a grid:
<stackpanel x:name="ExercisePositionSetter" margin="1255,3,0,0" height="2017" background="Transparent" panel.zindex="0">
<grid x:name="ExercisePositonSetterGrid">
<grid.columndefinitions>
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="160">
<columndefinition width="*">
<grid.rowdefinitions>
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="125">
<rowdefinition height="135">
<textblock grid.column="0" grid.row="0" grid.columnspan="2" horizontalalignment="Center" verticalalignment="Center"
="" foreground="{StaticResource KennetixDarkGreen}" fontsize="50" fontweight="SemiBold" textalignment="Center" text="Lever Height">
<textblock grid.column="3" grid.row="0" grid.columnspan="2" horizontalalignment="Center" verticalalignment="Center"
="" foreground="{StaticResource KennetixDarkGreen}" fontsize="50" fontweight="SemiBold" textalignment="Center" text="Lever Length">
<controls:motorsliderverticalcontrol
="" x:name="LeftHeight" horizontalalignment="Center" verticalalignment="top" grid.column="0" grid.row="1" grid.columnspan="2" grid.rowspan="10" tag="Lever Height - Left">
<controls:motorsliderverticalcontrol
="" x:name="LeftLeverLength" horizontalalignment="Center" verticalalignment="top" grid.column="3" grid.row="1" grid.columnspan="2" grid.rowspan="10" tag="Lever Length - Left">
Below are the methods for updating the view when the buttons click. I believe there is a way to know which control is being clicked on so I could update the control's values:
public void ShowInitialSetPositions()
{
ObservableCollection<motorviewmodel> tempMotorViewModels = new ObservableCollection<motorviewmodel>();
foreach (MotorViewModel motorVM in motorViewModels)
{
switch (motorVM.name)
{
case "Lever Height - Left":
tempMotorViewModels.Add(new MotorViewModel(motorVM.driver) { currentPos = motorVM.currentPos, SetPositon = SetLeverHeightLeft, name = motorVM.name, PresetPosition = SetLeverHeightLeft, TargetPosition = motorVM.TargetPosition, motorAssemblyDefaultParameters = motorVM.motorAssemblyDefaultParameters });
break;
case "Lever Length - Left":
tempMotorViewModels.Add(new MotorViewModel(motorVM.driver) { currentPos = motorVM.currentPos, SetPositon = SetLeverLengthLeft, name = motorVM.name, PresetPosition = SetLeverLengthLeft, TargetPosition = motorVM.TargetPosition, motorAssemblyDefaultParameters = motorVM.motorAssemblyDefaultParameters });
break;
}
}
motorViewModels = tempMotorViewModels;
}
public void AdjustPresetPositions(int delta)
{
ObservableCollection<motorviewmodel> tempMotorViewModels = new ObservableCollection<motorviewmodel>();
foreach (MotorViewModel motorVM in motorViewModels)
{
switch (motorVM.name)
{
case "Lever Height - Left":
tempMotorViewModels.Add(new MotorViewModel(motorVM.driver) { currentPos = motorVM.currentPos, SetPositon = SetLeverHeightLeft, name = motorVM.name, PresetPosition = motorVM.PresetPosition += delta, TargetPosition = motorVM.TargetPosition, motorAssemblyDefaultParameters = motorVM.motorAssemblyDefaultParameters });
break;
case "Lever Length - Left":
tempMotorViewModels.Add(new MotorViewModel(motorVM.driver) { currentPos = motorVM.currentPos, SetPositon = SetLeverLengthLeft, name = motorVM.name, PresetPosition = motorVM.PresetPosition += delta, TargetPosition = motorVM.TargetPosition, motorAssemblyDefaultParameters = motorVM.motorAssemblyDefaultParameters });
break;
}
}
motorViewModels = tempMotorViewModels;
}
Below are the converters for the Syncfusion slider that is used to set the values:
namespace Converters
{
public class CurrentPositionConverter : IValueConverter
{
public UIElement? UIParameter { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var rootElement = UIParameter as Border;
if (parameter != null)
{
var border = rootElement?.FindName(parameter.ToString());
var userControl = (border as Border).Parent;
var tag = (userControl as MotorSliderVerticalControl).Tag;
foreach (var item in value as ObservableCollection<motorviewmodel>)
{
if (item.name == tag.ToString())
{
return item.currentPos;
}
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
public class SetPositionConverter : IValueConverter
{
public UIElement? UIParameter { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var rootElement = UIParameter as Border;
if (parameter != null)
{
var border = rootElement?.FindName(parameter.ToString());
var userControl = (border as Border).Parent;
var tag = (userControl as MotorSliderVerticalControl).Tag;
foreach (var item in value as ObservableCollection<motorviewmodel>)
{
if (item.name == tag.ToString())
{
return item.SetPositon;
}
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
public class TargetPositionConverter : IValueConverter
{
public UIElement? UIParameter { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var rootElement = UIParameter as Border;
if (parameter != null)
{
var border = rootElement?.FindName(parameter.ToString());
var userControl = (border as Border).Parent;
var tag = (userControl as MotorSliderVerticalControl).Tag;
foreach (var item in value as ObservableCollection<motorviewmodel>)
{
if (item.name == tag.ToString())
{
return item.PresetPosition;
}
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
public class MaxTravelConverter : IValueConverter
{
public UIElement? UIParameter { get; set; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
var rootElement = UIParameter as Border;
if (parameter != null)
{
var border = rootElement?.FindName(parameter.ToString());
var userControl = (border as Border).Parent;
var tag = (userControl as MotorSliderVerticalControl).Tag;
foreach (var item in value as ObservableCollection<motorviewmodel>)
{
if (item.name == tag.ToString())
{
if (item.motorAssemblyDefaultParameters.ContainsKey("MotorMaxSteps"))
{
return item.motorAssemblyDefaultParameters["MotorMaxSteps"];
}
}
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}