Wpf ControlTemplate中的DataTrigger会中断多重绑定
我有下面的ControlTemplate,它工作得很好Wpf ControlTemplate中的DataTrigger会中断多重绑定,wpf,xaml,triggers,controltemplate,Wpf,Xaml,Triggers,Controltemplate,我有下面的ControlTemplate,它工作得很好 <ControlTemplate x:Key="TotalCostsStatisticTemplate"> <StackPanel x:Name="ContentHolderPanel" Visibility="Collapsed" Orientation="Horizontal" HorizontalAlignment="Center"> <TextBl
<ControlTemplate x:Key="TotalCostsStatisticTemplate">
<StackPanel x:Name="ContentHolderPanel" Visibility="Collapsed"
Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock x:Name="ValueTextBlock" VerticalAlignment="Center"
Style="{DynamicResource PhasingValueTextStyle}">
<TextBlock.Text>
<MultiBinding Converter="{ttConverters:CustomDisplayFormatConverter}">
<Binding Path="FormatSettings" />
<Binding Path="AvailableStatistics.CostsFormat"/>
<Binding Path="TotalCosts" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding ShowTotalCosts}" Value="True">
<Setter TargetName="ContentHolderPanel" Property="Visibility" Value="Visible"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
但是,如果我添加另一个DataTrigger,则TextBlock.Text上的多重绑定在首次加载使用此模板的控件时不起作用,即转换器CustomDisplayFormatConverter仅在所有值均为未设置值的情况下触发一次,不会再次触发(再次重新加载窗口时工作正常)
如果我把这个DataTrigger放在TextBlock.Style里面,它就可以正常工作了
知道怎么了吗
更新:
下面是如何使用它
<ControlTemplate x:Key="PhasingStatisticValuesTemplate">
<StackPanel x:Name="ContentHolderPanel" Orientation="Horizontal" Visibility="{Binding IsValid, Converter={StaticResource boolToVisibilityConverter}}">
<!-- Other control elements based on various templates -->
<Control Margin="20,10" Template="{DynamicResource TotalCostsStatisticTemplate}"/>
</StackPanel>
</ControlTemplate>
此PhasingStatisticValuesTemplate在另一个ControlTemplate中使用,然后在DataTemplate中使用,因此有一个很长的ControlTemplates层次结构-
<ControlTemplate x:Key="PhasingStatisticsTemplate">
<Grid>
<ScrollViewer Style="{DynamicResource CompactHorizontalScrollViewerStyle}" Name="ScrollContainer">
<Grid Name="ScrollViewerGrid" Background="Transparent">
<ContentControl Template="{DynamicResource PhasingStatisticValuesTemplate}" Name="ScrollViewerContent" />
</Grid>
</ScrollViewer>
</Grid>
</ControlTemplate>
另一个有用的信息。可能是文本块上的现有样式也更新了前台,但不确定这是如何导致此行为的-
<Style x:Key="PhasingValueTextStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsComplete}" Value="False">
<Setter Property="Foreground" Value="{DynamicResource ManagerErrorBrush}"/>
</DataTrigger>
</Style.Triggers>
</Style>
我无法使用您提供的XAML标记重现您的问题。如何应用控制模板
可能很重要。你能扩展你的例子吗?@dymanoid谢谢你的关注,我已经添加了更多的细节,但是很难提供完整的用法,因为它在非常复杂和冗长的窗口中使用。谢谢你提供更多细节。不幸的是,这个东西仍然没有问题,绑定在我的系统上工作。您是否尝试在转换器中设置断点,并比较堆栈轨迹的“好”和“坏”情况?@dymanoid是的,我这样做了,转换器只触发一次;第一次加载窗口时,所有绑定都会使用DependencyProperty.UnsetValue触发该窗口,并且不会再次触发该窗口。然而,如果没有DataTrigger,它可以正常工作,并且在属性更改时被多次激发。我无法使用您提供的XAML标记重现您的问题。如何应用控制模板
可能很重要。你能扩展你的例子吗?@dymanoid谢谢你的关注,我已经添加了更多的细节,但是很难提供完整的用法,因为它在非常复杂和冗长的窗口中使用。谢谢你提供更多细节。不幸的是,这个东西仍然没有问题,绑定在我的系统上工作。您是否尝试在转换器中设置断点,并比较堆栈轨迹的“好”和“坏”情况?@dymanoid是的,我这样做了,转换器只触发一次;第一次加载窗口时,所有绑定都会使用DependencyProperty.UnsetValue触发该窗口,并且不会再次触发该窗口。然而,它在没有DataTrigger的情况下工作良好,并且在属性更改时被多次激发。
<Style x:Key="PhasingValueTextStyle" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsComplete}" Value="False">
<Setter Property="Foreground" Value="{DynamicResource ManagerErrorBrush}"/>
</DataTrigger>
</Style.Triggers>
</Style>