Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to assign a value to <code>SelectedWorkCellGroup</code> property to do that.</p> <p>In you ViewModel's constructor, write following code:</p> <pre><code>if(WorkCellGroupInfoCollection.Any()) { SelectedWorkCellGroup = WorkCellGroupInfoCollection.First(); } </code></pre> <h2>Edit:</h2> <p>Following works for me:</p> <p>XAML:</p> <pre><code>&lt;Grid x:Name="LayoutRoot" Background="White"&gt; &lt;Border HorizontalAlignment="Center" VerticalAlignment="Center"&gt; &lt;ComboBox x:Name="WorkCellGroup" ItemsSource="{Binding WorkCellGroupInfoCollection}" SelectedItem="{Binding SelectedWorkCellGroup, Mode=TwoWay}" DisplayMemberPath="Name" /&gt; &lt;/Border&gt; &lt;/Grid&gt; </code></pre> <p>Code Behind:</p> <pre><code>public partial class ComboBoxSelectedItemTest : UserControl { public ComboBoxSelectedItemTest() { InitializeComponent(); DataContext = new ComboBoxSelectedItemTestViewModel(); } } public abstract class FilterBase { public string Id { get; set; } public string Name { get; set; } } public class WorkCellGroupInfo : FilterBase { } public class WorkCellGroupInfoCollection : ObservableCollection&lt;WorkCellGroupInfo&gt; { } public class ComboBoxSelectedItemTestViewModel : INotifyPropertyChanged { public WorkCellGroupInfoCollection WorkCellGroupInfoCollection { get; set; } public ComboBoxSelectedItemTestViewModel() { WorkCellGroupInfoCollection = new WorkCellGroupInfoCollection(); for (int i = 0; i &lt; 25; i++) { WorkCellGroupInfoCollection.Add(new WorkCellGroupInfo() { Id = String.Format("Id #{0}", i + 1), Name = String.Format("Name #{0}", i + 1) }); } SelectedWorkCellGroup = WorkCellGroupInfoCollection.First(); } private WorkCellGroupInfo _selectedWorkCellGroup; public WorkCellGroupInfo SelectedWorkCellGroup { get { return _selectedWorkCellGroup; } set { _selectedWorkCellGroup = value; RaisePropertyChanged("SelectedWorkCellGroup"); } } public event PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChanged(String propertyName) { PropertyChangedEventHandler temp = PropertyChanged; if (temp != null) { temp(this, new PropertyChangedEventArgs(propertyName)); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload