나는 진정한 초보자로서 나를 도울 수 있기를 바랍니다. 내 웹 서버의 SQL 데이터베이스에 바인딩 된 WPF 응용 프로그램이 있습니다. 데이터베이스를 업데이트하는 정보는 자동화 된 거래 플랫폼에서 이루어집니다. 이 응용 프로그램은 변경 사항을 실시간으로 모니터링하기 위해 설계되었습니다. 웹 서버의 데이터를 DataGrid에 바인딩하는 데는 아무런 문제가 없었습니다. 그러나 나는 실시간으로 DataGrid를 업데이트하는 방법을 알지 못합니다. 가장 가까운 방법은 클릭 할 때마다 응용 프로그램을 성공적으로 업데이트하는 새로 고침 단추를 추가하는 것입니다. 그러나 데이터베이스가 자동으로 변경 될 때마다 자체적으로 자동 업데이트하는 것이 좋습니다. 누군가이 코드를 수정하여이 작업을 수행하는 방법을 보여 주실 수 있습니까? 아래 코드를 배치했습니다. 감사!내 WPF 응용 프로그램에서 데이터 집합 새로 고침을 통해 내 데이터 그리드를 자동 업데이트하려고 시도합니다.
using System.Windows;
using Microsoft.Windows.Controls.Primitives;
using System.Collections.Generic;
using C1.WPF.DataGrid;
using StylingWPFGrid.ForexDataSetTableAdapters;
using System.Windows.Threading;
using System;
namespace StylingWPFGrid
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class WPFGrid : Window
{
private ForexDataSet _infoDataSet = null;
public ForexDataSet infoDataSet
{
get
{
if (_infoDataSet == null)
{
_infoDataSet = new ForexDataSet();
infoTableAdapter info = new infoTableAdapter();
info.Fill(_infoDataSet.info);
}
return _infoDataSet;
}
}
private ForexDataSet _tradesDataSet = null;
public ForexDataSet tradesDataSet
{
get
{
if (_tradesDataSet == null)
{
_tradesDataSet = new ForexDataSet();
tradesTableAdapter trades = new tradesTableAdapter();
trades.Fill(_tradesDataSet.trades);
}
return _tradesDataSet;
}
}
public WPFGrid()
{
InitializeComponent(); this.AccountsDataGrid.ItemsSource = infoDataSet.info;
InitializeComponent(); this.TradesDataGrid.ItemsSource = tradesDataSet.trades;
}
private void QuitBtn_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void RefreshBtn_Click(object sender, RoutedEventArgs e)
{
infoTableAdapter info = new infoTableAdapter();
info.Fill(_infoDataSet.info);
}
}
}
의견을 보내 주셔서 감사합니다. 구성 요소 초기화 및 TwoWay에 대한 바인딩 설정을 완료했습니다. 내 코드 내에서 INotifyPropertyChange를 정확히 배치해야하는 문제가 있지만 계속 유지할 것입니다. 다시 한번 감사드립니다. – Stan
인터페이스를 배치해야하는 위치를 보여주기 위해 코드가 업데이트되었습니다. – Billy
빌리, 나는 당신이 보여준대로 모든 것을 삽입하려고 시도했는데 내가 그 일을 할 때 한 줄의 빨간색 밑줄 오류가 있었고 라인의 마지막 "e"아래에 있었다 : PropertyChanged (this, new PropertyChangedEventArgs (e)); 그러나 응용 프로그램을 실행할 때 오류나 경고가 없었으며 응용 프로그램이 시작되어 새로 고침되지 않았습니다. – Stan