在組合框更改後,我的圖表需要更新。這一切都沒有發生,它沒有更新到我的負載func。組合框更新動態條形圖更改
組合框正在正確填充。和負載圖表功能也正常輸入
「真的----幫助需要!!!!」
XAML文件
<StackPanel Grid.Column="1" >
<ComboBox x:Name="SelectNameCB" FontSize="15" Margin="11,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="207" ItemsSource="{Binding MyComboBoxData}" SelectedItem="{Binding selectedcb, Mode=Default, UpdateSourceTrigger=PropertyChanged}" SelectedIndex="0" />
<DVC:Chart x:Name="mcChart" Margin="10,10,31,0" Height="273" Background="LightGoldenrodYellow" Title="{Binding Text, ElementName=SelectNameCB}" >
<DVC:BarSeries Title="Avg. Score" IndependentValueBinding="{Binding Key}" DependentValueBinding="{Binding Value}" ItemsSource="{Binding ChartData}" Margin="10,10,76,10" AnimationSequence="LastToFirst"/>
</DVC:Chart>
視圖模型文件 - fbvm
namespace charting
{
class fbvm : ViewModelBase, INotifyPropertyChanged
{
public String eID, loadtoc="A_M";
private List<KeyValuePair<string, float>> _chartData;
public List<KeyValuePair<string, float>> ChartData
{
get
{
return _chartData;
}
set
{
_chartData = value;
OnPropertyChanged(() => ChartData);
}
}
private List<string> _MyComboBoxData;
public List<string> MyComboBoxData
{
get
{
return _MyComboBoxData;
}
set
{
_MyComboBoxData = value;
OnPropertyChanged(() => MyComboBoxData);
}
}
private string _selectedcb;
public string selectedcb
{
get
{
loadtoc = _selectedcb;
return _selectedcb;
}
set
{
_selectedcb = value;
OnPropertyChanged(() => selectedcb);
}
}
public fbvm()
{
MyComboBoxData = new List<string>();
comboboxload();
ChartData = new List<KeyValuePair<string, float>>();
LoadColumnChartData(loadtoc);
}
private void comboboxload()
{
OleDbConnection ConDb;
ConDb = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Admin\\Documents\\Visual Studio 2012\\Projects\\Feedback\\Feedback.accdb");
try
{
ConDb.Open();
OleDbCommand DBSelect = new System.Data.OleDb.OleDbCommand("select FName, LName,ID_NAME from NameList", ConDb);
OleDbDataReader reader = DBSelect.ExecuteReader();
while (reader.Read())
{
string eNAME = "";
eID = reader["ID_NAME"].ToString();
eNAME += reader["FName"].ToString();
eNAME += " " + reader["LName"].ToString();
MyComboBoxData.Add(eNAME);
}
}
catch (Exception ae)
{
MessageBox.Show(ae.Message);
}//catch
}
public void LoadColumnChartData(string loadtodb)
{
int cc1=0,tc1=0,aa1=0,blfe1=0,count=0;
float cc11 = 0, tc11 = 0, aa11 = 0, blfe11 = 0;
string str = loadtoc;
string[] output = str.Split(' ');
foreach (string s in output)
{ loadtodb = str[0] + "_";
}
OleDbConnection connect = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Admin\Documents\Visual Studio 2012\Projects\Feedback\Feedback.accdb");
connect.Open();
string query = "select CC,TC,AA,BLFE,WMU from " +loadtoc;
OleDbCommand select = new OleDbCommand("select", connect);
select.CommandText = query;
OleDbDataReader reader = select.ExecuteReader();
while (reader.Read())
{
cc1 += Int32.Parse(reader[0].ToString());
tc1 += Int32.Parse(reader[1].ToString());
aa1 += Int32.Parse(reader[2].ToString());
blfe1 += Int32.Parse(reader[3].ToString());
++count;
}
cc11 =(float) cc1/count; aa11 =(float) aa1/count;
tc11 =(float) tc1/count; blfe11 =(float) blfe1/count;
ChartData.Add(new KeyValuePair<string, float>("cc", cc11));
ChartData.Add(new KeyValuePair<string, float>("tc", tc11));
ChartData.Add(new KeyValuePair<string, float>("aa", aa11));
ChartData.Add(new KeyValuePair<string, float>("blfe", blfe11));
ChartData = new List<KeyValuePair<string, float>>(ChartData);
}//loadcoloumnchart
#region INotifyPropertyChanged Members
/// <summary>
/// Need to implement this interface in order to get data binding
/// to work properly.
/// </summary>
/// <param name="propertyName"></param>
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}//class fbvm
} //命名空間