Это мой XAML
Код: Выделить всё
Код: Выделить всё
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
namespace WpfApp1
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public MainWindow()
{
InitializeComponent();
MyItems =
[
new MyItem() { Text = "Val 0", Value = 0 },
new MyItem() { Text = "Val 1", Value = 1 },
new MyItem() { Text = "Val 2", Value = 2 },
];
// Pre-Select Value 1
MySelectedValue = 1;
DataContext = this;
}
public ObservableCollection MyItems { get; private set; }
public int _mySelectedValue;
public int MySelectedValue
{
get => _mySelectedValue;
set
{
_mySelectedValue = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MySelectedValue)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(MySelectedText)));
}
}
public string MySelectedText
{
get => $"Value is {MySelectedValue}";
}
}
public class MyItem
{
public string Text { get; set; }
public int Value { get; set; }
}
}
Код: Выделить всё
MySelectedValueЧто мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/798 ... cted-value