我有个习惯
TreeListView
(基于
TreeView
)在我的WPF应用程序中。这个
ItemSource
绑定到
ObservableCollection<Node>
哪里
Node
是基于
TreeListViewItem
因此
TreeItem
。它包含应显示的值。
列与
节点
在加载新节点时工作(我实现了lazyload,ItemSource经常更改(新
节点
s已添加),UI也是如此),但当节点中的值更改时,UI中的值不会更改。
我创建了
DataTemplate
具有测试行为的触发器:
<DataTemplate x:Key="CellTemplate_Speicherplatz">
<TextBlock Name="tbSpeicherplatz" TextAlignment="Right">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Text" Value="{Binding RecSpeicherplatz, RelativeSource={RelativeSource AncestorType={x:Type k:Node}}}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding DataContext.IsProcessing, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="False">
<Setter Property="Text" Value="{Binding RecSpeicherplatz, RelativeSource={RelativeSource AncestorType={x:Type k:Node}}}"/>
</DataTrigger>
<DataTrigger Binding="{Binding DataContext.IsProcessing, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Value="True">
<Setter Property="Text" Value="..."/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</DataTemplate>
这会导致以下行为:而
IsProcessing
为true,则UI中的文本为“…”。什么时候
正在处理
更改为false,旧值为
RecSpeicherplatz
即使变量已在
节点
.
有人能解释一下为什么会这样,以及如何解决这个问题吗?