It is necessary to implement a table (DataGrid), which is initially empty. It has 2 fields: The current date and the item selected from the ComboBox. How to refer to ComboBox'u if it's impossible by x:Name'u?
Here is an code:
plusBtn.Click += (source, e) =>
{
var tableStr = new SpecialDays
(
date: DateTimeOffset.Now
);
timeTableData.Add(tableStr);
};
DataGridTemplateColumn Header="Суточное расписание"
Width="50*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Time}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{StaticResource TableList}"
SelectedIndex="0"
x:Name="cmb"
SelectedItem="{Binding TimeTableList, Mode=OneWay}"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
Вот класс который создает экземпляр объекта:
public class SpecialDays
{
public DateTimeOffset Date { get; set; }
public int Time { get; set; }
public ObservableCollection<int> TimeTableList { get => timeTableList; set => timeTableList = value; }
private ObservableCollection<int> timeTableList = new();
public SpecialDays(DateTimeOffset date, ObservableCollection<int> timeTable)
{
Date = date;
TimeTableList = timeTable;
}
public SpecialDays()
{
}
public SpecialDays(DateTimeOffset date, int timeTable)
{
Date = date;
Time = timeTable;
}
public SpecialDays(DateTimeOffset date)
{
Date = date;
}
}
What I have tried:
<!--<DataGridComboBoxColumn Header="Суточное расписание"
ItemsSource="{Binding TableList}"
Width="50*"
IsReadOnly="False"
SelectedItemBinding="{Binding TimeTableList}"
TextBinding="{Binding Time}"
x:Name="cmbBox">
--><!--<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="ItemsSource"
Value="{StaticResource TableList}"/>
<Setter Property="SelectedItem"
Value="{Binding TimeTableList, Mode=OneWay}"/>
<Setter Property="SelectedIndex"
Value="0"/>
</Style>
</DataGridComboBoxColum<pre><pre lang="XML">
n.EditingElementStyle>-->