I'm racking my head with the following:
When I run the code and make selection: Item1
I get the result: System.Windows.Controls.ComboBoxItem: Item1
Instead of just: Item1
What am I doind wrong?
The Equity.cs:
namespace ComboBoxText { class Equity : INotifyPropertyChanged { private string country; public string Country { get { return country; } set { country = value; OnPropertyChanged("Country"); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); Debug.Print($" changed: {Country}"); } } }the main code
public partial class MainWindow : Window { Equity ET = new Equity(); public MainWindow() { InitializeComponent(); this.DataContext = ET; } }
The xaml code:
<Grid><StackPanel><ComboBox x:Name="Country4" Height="35" Width="200" Margin="20,20,20,20" SelectedItem ="{Binding Country, Mode=TwoWay}"><ComboBoxItem>Item1</ComboBoxItem><ComboBoxItem>Item2</ComboBoxItem></ComboBox><TextBox x:Name="Txtbx1" Width="500" Height="30" Text="{Binding Path = Country}"></TextBox></StackPanel></Grid>