У меня есть приложение WPF и используйте UserControl как представление. Внутри этого UserControl есть DevExpress ComboBoxEdit.Как выбрать первый элемент в DevExpress ComboBoxEdit?
<UserControl ...
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<dxe:ComboBoxEdit Name="ComboBoxInspectionList" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding InspectionList}" SelectedItem="{Binding SelectedInspection}" IsTextEditable="False"/>
</Grid>
</UserControl>
ComboBox связан данными. Я пробовал:
public partial class InspectionList : UserControl
{
public InspectionList()
{
InitializeComponent();
if (ComboBoxInspectionList.Items.Count > 0)
{
ComboBoxInspectionList.SelectedIndex = 0;
}
}
}
Но привязка данных произошла после выполнения кода в конструкторе UserControl.
Просто установите из конструктора ViewModel что-то вроде SelectedInspection = InspectionList.FirstOrDefault() – 3615