Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
 private List<ListItem>  _tyreList;
public List<ListItem> TyreList;
{
  get
    {
                return _tyre;
     }
    set
      {
                _tyre= value;
                RaisePropertyChanged();
      }
}

<ComboBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="1"  SelectedValuePath="Value" DisplayMemberPath="Name" ItemsSource="{Binding ElementName=LayoutRoot, Path=DataContext.TyreList}" SelectedItem="{Binding TyreList}"/>

                                        
<Button Command="{Binding AddTyreCommand}" Grid.Row="3" Grid.Column="4" Grid.ColumnSpan="2" Content="Add Tyre"  Width="150" Height="25" HorizontalAlignment="Left" />
                                        
<TextBox  Name="tbMultiLine"  TextWrapping="Wrap"  AcceptsReturn="True"  VerticalScrollBarVisibility="Visible" Text="{Binding what binding to set here => TyreList}" />


What I have tried:

C#
private RelayCommand _addTyreCommand;
public RelayCommand AddTyreCommand => _addTyreCommand?? (_addTyreCommand= new RelayCommand(AddTyres , CanAddTyres));
   
private void AddTyres ()
{
//something here

 }      

 private bool CanAddTyres() => true;//to add tyres
Posted
Updated 11-Nov-18 18:59pm
v2

1 solution

OK
First
Create a public ListItem property and Bind it to TextBox

C#
public ListItem SelectedItem 
{
  get=>selectedItem;
  set
     {
      selectedItem=value;
      RaisePropertyChange();
     }
}

HTML
<TextBox Text = "{Binding SelectedItem, UpdateSourceTrigger=PropertyChanged}"/>



Second use RelayCommand which accepts command parameter like
C#
RelayCommand<object> AddtyreCommand=> -----new RelayCommand(Addtyres)
where 
private void AddTyres(object item)
{
   SelectedItem  = item as ListItem;
.......
}



Third set Name to combobox and In Button Define CommandParameter
HTML
<Button .... CommandParameter="{Binding ElementName=comboTyreList, Path=SelectedItem" />


Thats it. You are done.
Sorry for inappropriate formatting and code.
 
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