Click here to Skip to main content
15,888,209 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i need to set the value of a list of strings and get it from a selecteitem, this is my XAML
XML
<ComboBox Name="ComboTipoPpa" Grid.Row="10" Grid.Column="1"
                      Height="26" Width="177" 
                      HorizontalAlignment="Left" 
                      Margin="10,1,0,1"
                      IsEnabled="{Binding ElementName=cbAgregarManual, Path=IsChecked}" 
                       ItemsSource="{Binding Path=ListTipoPpa, ValidatesOnNotifyDataErrors=False}" 
                      SelectedItem="{Binding Path=XXXXXX, Mode=TwoWay, NotifyOnValidationError=True}" />


the list in my mvvm (i'm using microsoft Prism)

public List<string> ListTipoPpa
{
    get
    {
        List<String> data = new List<string>();
        data.Add(ControlesResource.TextoTipoPPAConexion);
        data.Add(ControlesResource.TextoTipoPPAEjecutor);
        data.Add(ControlesResource.TextoTipoPPASTR);
        return data;
    }

}

** Note ** ControlesResource.TextoTipoPPAConexion this is from a resource file

What I have tried:

I think that I should do is this
public List<string> ListTipoPpa
{
    get
    {
        List<String> data = new List<string>();
        data.Add(ControlesResource.TextoTipoPPAConexion);
        data.Add(ControlesResource.TextoTipoPPAEjecutor);
        data.Add(ControlesResource.TextoTipoPPASTR);
        return data;
    }
    set
    {
        a_Variable_Defined_as_int = value;
            this.RaisePropertyChanged(() => this.ListTipoPpa);
    }
}


Any suggest
Posted
Updated 16-Dec-19 3:34am

1 solution

You can bind the SelectedItem property in the combo box to a public property in your form. That means your form has to inherit/implement INotifyPropertyChanged.

Another way is to handle the SelectionChanged event for the combo box, and set a method variable like so:

MyType selected = (MyType)combobox.SelectedItem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900