Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
465
Combobox field bound to a collection of class
posted

Hello,

I would like to have a column as a combobox, where I can make a choice and that selectedItem shall be then saved in a property in the ViewModel.

The underlying CashflowScenarioUnitModel has a Name (string) property, ScenarioID (int)   

public List<CashflowScenarioUnitModel> ScenarioNames
{
    get { return CashflowScenarioUnitDropDowns;}
}

public CashflowScenarioUnitModel Scenario
{
   
getreturn  _cashflowUnitScenarioModel; }
   
set{  
           
if (_cashflowUnitScenarioModel == value)
            {
              
return;
             }
     RaisePropertyChanged(Scenario);
    }
}

<igDP:Field Name="Scenario">
   <igDP:Field.Settings>
      <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}">
         <igDP:FieldSettings.EditorStyle>
            <Style TargetType="{x:Type igEditors:XamComboEditor}">
            <Setter Property="ItemsSource" Value="{Binding DataItem.ScenarioNames}"/>
            <Setter Property="DisplayMemberPath" Value="Name"/>
            <Setter Property="ValuePath" Value="ScenarioID" />
          </Style>
        </igDP:FieldSettings.EditorStyle>
     </igDP:FieldSettings>
    </igDP:Field.Settings>
</igDP:Field>

The problem is already in the xaml that I dont want to bind to the ScenarioID, but rather to the selectedItem within the bound collection and store that selection into the Scenario property. How would I do that?

And another question is, some utilise a CollectionView and inject the List<ViewModel> in it. How is this advantageous?

Many Thanks for your help,
Houman