我在后台工作线程的已完成方法中设置对象的DataContext.出于某种原因,我收到一个错误说:
此时无法修改此节点的逻辑子节点,因为正在进行树步行指向Chart1.DataContext = allDates行.
树木行走的意义何在?我已经尝试使用Dispatcher操作执行此设置,并且出现相同的错误...任何想法?谷歌在这个错误消息上没有任何结果.
代码导致这是微软Charting工具包的内部......我想知道我是否在他们的控制中发现了一个错误......
没有Dispatcher:
void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
ArticlesPerTimePeriodResult result = (ArticlesPerTimePeriodResult)e.Result;
lvArticles.ItemsSource = result.DatesOfArticles;
Chart1.DataContext = result.AllDates;
}
Run Code Online (Sandbox Code Playgroud)
使用Dispatcher:
void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
ArticlesPerTimePeriodResult result = (ArticlesPerTimePeriodResult)e.Result;
lvArticles.ItemsSource = result.DatesOfArticles;
Dispatcher.BeginInvoke((Action<List<KeyValuePair<DateTime,int>>>)(delegate(List<KeyValuePair<DateTime,int>> allDates)
{
Chart1.DataContext = allDates;
}), result.AllDates);
//Chart1.DataContext = result.AllDates;
}
Run Code Online (Sandbox Code Playgroud)
错误:
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, …Run Code Online (Sandbox Code Playgroud) 我正在使用Microsoft CodePlex项目中的WPF数据网格.我有一个自定义控件,我想从数据网格的行数据绑定到一个字段.我不能为我的生活弄清楚如何在datagrid行上指定工具提示.
我最接近的是使用带有Setter的RowStyle来设置工具提示,但这似乎只适用于文本.当我尝试将ControlTempalte作为ToolTip的值时,它会显示在ControlTemplate类型上调用ToString的结果.
我想我需要设置ToolTip的"Template"属性,但我似乎无法弄清楚如何做到这一点......
<dg:DataGrid Name="dgResults" AutoGenerateColumns="True">
<dg:DataGrid.RowStyle >
<Style TargetType="{x:Type dg:DataGridRow}">
<Setter Property="ToolTip" >
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToolTip}">
<StackPanel>
<TextBlock>txt1</TextBlock><TextBlock>txt2</TextBlock>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</dg:DataGrid.RowStyle>
</dg:DataGrid>
Run Code Online (Sandbox Code Playgroud)