这是我的情景: 我正在使用这个TreeView:
<s:SurfaceWindow .... >
<Grid>
.....
<TreeView Name="DriveTree" Margin="5" Height="300" Width="300" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" >
<s:SurfaceButton Click="CloseApplication">Chiudi applicazione</s:SurfaceButton>
</TreeView>
</Grid>
</s:SurfaceWindow>
我有一个计时器,每个X秒控制新的外部插入驱动器,并且经过它调用此功能:
public void GetRemovableDrives()
{
//drives variable is a list of driveInfo where I save active drives
DriveInfo[] dInfos = DriveInfo.GetDrives();
List<int> dInfosToRemove = new List<int>();
foreach (DriveInfo si in dInfos)
if (drives.Find(x => x.Name == si.Name) == null && si.IsReady && MtUtilities.IsProjectOnExternalDisk(si.Name))
{
drives.Add(si);
DriveTree.Items.Add(this.GetItem(si));
}
for (int i = 0; i < drives.Count(); i++)
if (!dInfos.Select(x => x.Name).Contains(drives[i].Name))
dInfosToRemove.Add(i);
foreach (int d in dInfosToRemove)
{
drives.RemoveAt(d);
DriveTree.Items.RemoveAt(d + 2);
}
}
当我第一次调用时(在Window构造函数中)它就像一个魅力,但是当它被计时器调用时它会删除或添加DriveTree中的项目(如果我暂停调试,我可以看到该元素被添加/删除了项目列表由一个直接窗口)但应用程序中的visibile treeView没有更新,它没有显示新项目,就像用户界面没有得到它们。 有什么想法吗?