Skip to content

Instantly share code, notes, and snippets.

Created September 2, 2015 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0ab6c7bf37c29538a3a3 to your computer and use it in GitHub Desktop.
Save anonymous/0ab6c7bf37c29538a3a3 to your computer and use it in GitHub Desktop.
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<ComboBox ItemsSource="{Binding C}" SelectedValue="{Binding S}"/>
<Button Click="ButtonBase_OnClick">B</Button>
<Button Click="ButtonBase_OnClick2">B2</Button>
</StackPanel>
</Grid>
</Window>
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
namespace WpfApplication6
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
private int s;
private IEnumerable<int> c = new ObservableCollection<int>();
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}
public int S
{
get { return s; }
set
{
s = value;
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("S"));
}
}
}
public IEnumerable<int> C
{
get { return c; }
set
{
c = value;
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("C"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
S = 1;
}
private void ButtonBase_OnClick2(object sender, RoutedEventArgs e)
{
C = new ObservableCollection<int> { 2, 3 };
C = new ObservableCollection<int> { 1, 2 };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment