В соответствии с комментариями я приведу небольшой пример того, как это можно сделать (я добавил 1-2 дополнения, которые могут быть полезны для этого)
Используйте Text="{Binding Value}"
для привязки к значениюв ВМ
Используйте Wrappanel
, чтобы отобразить его горизонтально
(необязательно). Используйте AlternationIndex
, чтобы обозначить Коэффициенты
(необязательно). Измените FlowDirection
чтобы отобразить его так, как вы нарисовали его
<!-- Combobox to select from the available Grades and store the selected in the SelectedGrade -->
<ComboBox ItemsSource="{Binding AvailableGrades}" SelectedValue="{Binding SelectedGrade}" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<!-- Use Alternationcount to label the coefficients properly and Flowdirection to keep a0 on the right side -->
<ItemsControl ItemsSource="{Binding Coefficients}" AlternationCount="11" FlowDirection="RightToLeft">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!-- Textbox to enter Coefficient (eg. a0 would be SelectedGrade[0] in code)-->
<TextBox Text="{Binding Value}" Width="50" VerticalAlignment="Center"/>
<!-- Labeling of the Coefficient using the AlternationIndex and a String Format -->
<Label Content="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource TemplatedParent}}" ContentStringFormat="a{0}"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
<!-- Use a WrapPanel as ItemsPanel to align the Entries horizontally -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
И выглядит так (без текстового поля оценки, только материал с правой стороны)
РЕДАКТИРОВАТЬ
Чтобы правильно настроить количество коэффициентов, требуется немного логики, но сначала -> Переименуйте свойства соответствующим образом и определите их возможное значение (это помогает создать соответствующее значение).логика для свойств)
AvailableGrades = 0, 1, 2 ... 10
SelectedGrade ∈ {0, 1, 2 ... 10}
Коэффициенты = a (0), a (1) ... a (Выбранный класс)
//Unfortunately it is not possible to use a Value Type and bind to it due it has no Getter/Setter therefore we need a little wrapper
public class ValueTypeAsClass<T>
{
public T Value { get; set; }
public static implicit operator ValueTypeAsClass<T>(T v)
{
return new ValueTypeAsClass<T> { Value = v };
}
public static implicit operator T(ValueTypeAsClass<T> v)
{
return v.Value;
}
}
//member variable for select grade
private int _selectedGrade = 0;
//List of Coefficients (renamed from SelectedGrade)
public ObservableCollection<ValueTypeAsClass<double>> Coefficients { get; set; } = new ObservableCollection<ValueTypeAsClass<double>>() { 0d };
//Available (valid) Grades to select from in the ComboBox
public List<int> AvailableGrades { get; private set; } = Enumerable.Range(0, 11).ToList();
//Currently selected grad with logic to adjust the coefficient amount
public int SelectedGrade
{
get { return _selectedGrade; }
set
{
_selectedGrade = value;
//Clear Coefficients and add the necessary amount
Coefficients.Clear();
for (int i = 0; i <= _selectedGrade; i++) { Coefficients.Add(0); }
}
}