我目前正在升级我的前任的工具,但我遇到了一个TreeView
问题。他的软件对数据进行了一次分析,并将结果显示在TreeView
. 我更改了工具来分析实时数据,因此用户可以获得实时结果。现在,我希望树视图节点在用户展开时保持展开,即使在更新之后也是如此。我知道这个话题已经讨论过好几次了,我花了几个小时阅读答案,但我从来没有找到解决我的问题的方法。
基本问题是:不再有稳定的树,目前每次都重新创建树。到目前为止,我对数据绑定或 XAML 一无所知,也很少有时间学习 XAML 编程。您可以在下面看到类似于我的前任创建的代码。到目前为止我没有改变任何东西,我只是每 2-5 秒调用一次这个方法。
是否有一种(简单的?)方法可以将有关扩展节点的信息存储在任何地方(全局?)并在刷新后重新扩展它,还是我真的需要先更深入地了解 WPF?
foreach (Analyzer.ALARM_GROUP alarmGroup in alarmGroupList)
{
//Display Problem Group
TreeViewItem groupItem = new TreeViewItem();
List<String> ListAreas = new List<string>();
string areas = "";
//GROUP HEADER
//display alarm group which contains more than one alarm
if (alarmGroup.AlarmList.Count > 1)
{
groupItem.Header = Convert.ToString(alarmGroup.AlarmList.Count) + " --- " + alarmGroup.AlarmList[0].EventTime + " " + alarmGroup.AlarmList[0].AlarmText + "\n "
+ alarmGroup.AlarmList[alarmGroup.AlarmList.Count - 1].EventTime + " " + alarmGroup.AlarmList[alarmGroup.AlarmList.Count - 1].AlarmText
+ " --- " + " AREAS: " + areas;
}
else //display alarm group with only one alarm message
{
groupItem.Header = Convert.ToString(alarmGroup.AlarmList.Count) + " --- " + alarmGroup.AlarmList[0].EventTime + " " + alarmGroup.AlarmList[0].AlarmText + " --- " + " AREA: " + areas;
}
//HEADLINE of single Alarm Item
TreeViewItem alarmItem = new TreeViewItem();
alarmItem.Header = "[EVENTTIME] [ALARMTAG] --- [OPCCONDITION] --- [SEVERITY] --- [AREA] --- [ALARMTEXT]";
alarmItem.FontWeight = FontWeights.SemiBold;
groupItem.Items.Add(alarmItem);
//Display single alarm messages
foreach (var alarm in alarmGroup.AlarmList)
{
alarmItem = new TreeViewItem();
alarmItem.Header = alarm.EventTime + " --- " + alarm.AlarmTag + " --- " + alarm.Condition + " --- " + alarm.Severity + " --- " + alarm.Area + " --- " + alarm.AlarmText;
alarmItem.FontWeight = FontWeights.Normal;
groupItem.Items.Add(alarmItem);
}
AlarmPresentationBox.Items.Add(groupItem);