データグリッドにバインドされた監視可能なコレクションがあります...ヘッダーをクリックしてデータグリッドを並べ替えたいです。動的データです。これが私のコードです
namespace SLSortObservableCollection
{
public partial class MainPage : UserControl
{
//ObservableCollection<int> NumData = new ObservableCollection<int>();
// ObservableCollection<string> StrData = new ObservableCollection<string>();
public MainPage()
{
InitializeComponent();
ObservableCollection<int> NumData = new ObservableCollection<int>();
ObservableCollection<string> StrData = new ObservableCollection<string>();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Random ra = new Random();
for (int i = 0; i < 10; i++)
{
int num = ra.Next(1000);
NumData.Add(num);
}
try
{
dataGrid1.ItemsSource = null;
dataGrid1.ItemsSource = NumData;
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
private void button2_Click(object sender, RoutedEventArgs e)
{
try
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for (int i = 0; i < 5; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
StrData.Add(builder.ToString());
}
dataGrid1.ItemsSource = StrData;
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
}
}