此时无法修改此节点的逻辑子节点,因为树遍历正在进行中
我有两个 wpf 工具包图表,一个是饼图,第二个是条形图系列,
我有仅在表单加载时调用的方法,
chartGuest.DataContext = null;
List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
HProDataContext db = new HProDataContext();
var _RoomTypes = (from d in db.roomtypes select d.roomtype1).ToList();
var _RoomTypeID = (from d in db.roomtypes select d.id).ToList();
int count = 0;
for (int i = 0; i < _RoomTypeID.Count; i++)
{
count = Convert.ToInt32((from d in db.actions where d.room.roomtypeid == _RoomTypeID[i] select d.id).Count());
valueList.Add(new KeyValuePair<string, int>(_RoomTypes[i], count));
}
chartGuest.DataContext = valueList;
它给出了这样的错误:此时无法修改此节点的逻辑子节点,因为正在进行树遍历。
相同的代码在饼系列图表上效果很好。
这是我的图表:
<charting:Chart x:Name="chartRoomType" Width="402" Height="255" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="15,275,0,0">
<charting:Chart.Series>
<charting:PieSeries ItemsSource="{Binding}" DependentValuePath="Value" IndependentValuePath="Key" Title="Room Types" IsSelectionEnabled="True" />
</charting:Chart.Series>
</charting:Chart>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="314,292,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="28,296,0,0" Name="textBlock4" Text="Room Types" VerticalAlignment="Top" />
<charting:Chart x:Name="chartGuest" Height="269" VerticalAlignment="Top" Margin="6,0" Title="Guests">
<charting:Chart.Series>
<charting:BarSeries ItemsSource="{Binding}" DependentValuePath="Value" IndependentValuePath="Key" Title="Room Types" IsSelectionEnabled="True" />
</charting:Chart.Series>
</charting:Chart>
有人可以帮助我吗? PS我发现了这个问题,但没有帮助 什么是由于树遍历正在进行中,因此无法修改此节点的逻辑子节点是什么意思?
I have two wpf tool kit charts one is pie chart and second bar series
i have method which i call only on form load
chartGuest.DataContext = null;
List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
HProDataContext db = new HProDataContext();
var _RoomTypes = (from d in db.roomtypes select d.roomtype1).ToList();
var _RoomTypeID = (from d in db.roomtypes select d.id).ToList();
int count = 0;
for (int i = 0; i < _RoomTypeID.Count; i++)
{
count = Convert.ToInt32((from d in db.actions where d.room.roomtypeid == _RoomTypeID[i] select d.id).Count());
valueList.Add(new KeyValuePair<string, int>(_RoomTypes[i], count));
}
chartGuest.DataContext = valueList;
It gaves such error : Cannot modify the logical children for this node at this time because a tree walk is in progress.
The same code works great on pie series chart.
This is my charts:
<charting:Chart x:Name="chartRoomType" Width="402" Height="255" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="15,275,0,0">
<charting:Chart.Series>
<charting:PieSeries ItemsSource="{Binding}" DependentValuePath="Value" IndependentValuePath="Key" Title="Room Types" IsSelectionEnabled="True" />
</charting:Chart.Series>
</charting:Chart>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="314,292,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="28,296,0,0" Name="textBlock4" Text="Room Types" VerticalAlignment="Top" />
<charting:Chart x:Name="chartGuest" Height="269" VerticalAlignment="Top" Margin="6,0" Title="Guests">
<charting:Chart.Series>
<charting:BarSeries ItemsSource="{Binding}" DependentValuePath="Value" IndependentValuePath="Key" Title="Room Types" IsSelectionEnabled="True" />
</charting:Chart.Series>
</charting:Chart>
Can anyone help me?
P.s. i found this question but it was unhelpful
What does Cannot modify the logical children for this node at this time because a tree walk is in progress mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 DataPointSeries.ItemsSource 绑定到数据上下文。
假设这是窗口面板的 XAML,其中数据网格和图表控件共享一个公共列表作为
ItemsSource
。在后面的代码中,我们重置窗口的数据上下文...
每次单击按钮时,图表都会刷新而不会出现错误。
让我知道这是否有帮助。
Use DataPointSeries.ItemsSource to bind to the data context.
Assuming that this is XAML of your your window panel that has the datagrid and charting control sharing a common list as
ItemsSource
..In code behind we reset the data context of the window ....
Everytime you click the button the chart refreshes without error.
Let me know if this helps.
我在不同的情况下收到了相同的异常。我使用的代码收集现有 UIElements 并创建新的 UIElement 并将第一个设置为第二个 UIElement 的内容。此外,它从现有 UIElement 中获取属性值并将其设置为新 UIElement 的不同属性的值。
但在这种情况下,内部属性的 Title 可以是 Binding,但上面的代码仅复制值,并且当 insideElement.Title 绑定到某个源时,outsideElement.Header 不会反映更改。
所以我更改了代码将 HeaderProperty 绑定到 insideElement 的 TitleProperty:
但是当我执行上面的代码时,我收到了
我发现我无法将一个依赖属性绑定到存储在 Content 属性内的另一个依赖属性。
我尝试获取innerUIElement 的绑定表达式并将其设置为outsideUIElement 的HeaderProperty 的新绑定。
现在,外部 UI 元素绑定到相同的源,并且 WPF 演示器不会抛出异常。我的问题解决了。
I've received the same exception in different situation. I work with code which takes collection of existing UIElements and create new UIElement and set first one as Content of second one. Aditionally, it takes property value from existing UIElement and set it as value of different property of new UIElement.
But in this case Title of inside property can be a Binding, but code above copies only value and when insideElement.Title is bounded to some source, outsideElement.Header doesn't reflect change.
So I changed code to bind HeaderProperty to TitleProperty of insideElement:
But when I executed code above, I received
I found that I can't bind one dependency property to another one, which is stored inside Content property.
I tried to get binding expression of innerUIElement and set it as new binding to HeaderProperty of outsideUIElement.
Now, outer UI Element is binded to same source and WPF presenter doesn't throw Exception. My problem is solved.
我知道这已经有一段时间了,但为了防止其他人遇到它,我找到了另一种方法。将图表放入 StackPanel 中,创建时可见性为“折叠”(“隐藏”不起作用)。然后在第一次设置 DataContext 后将可见性设置为“Visible”(我每次都会这样做,但在第一次之后它是多余的)。
我的经验与我看到的报告一致,问题是在有一个空的 DataContext 之后设置一个非空的 DataContext 时发生的错误;但显然,如果图表折叠,它不会执行“树行走”。
I know this has been a while, but in case anyone else comes across it I found another way around it. Put the chart into a StackPanel, created with Visibility of "Collapsed" ("Hidden" DOES NOT WORK). Then set visibility to "Visible" after setting DataContext the first time (I'm doing it every time, but after the first it's redundant).
My experience agrees with reports I've seen that the problem is a bug that occurs when setting a non-empty DataContext after having had an empty one; but apparently it doesn't do the "tree walk" if the chart is collapsed.