一段时间后,UI不会基于触发器进行更新

时间:2018-12-10 12:15:18

标签: c# wpf data-binding snoop

我创建了一个自定义控件,如下所示: CollapseView

如果用户单击右侧的图标,即Checkbox(自定义CheckBox),则ListBox项将展开,并且CheckBox图标将更改,如下所示 ExpandView

下面是Xaml代码

<CheckBox  x:Name="ExpandCheckBox" IsChecked="{Binding HasExpanded,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                <CheckBox.Resources>
                                    <SolidColorBrush x:Key="CircleStrokeHighlightBrush" Color="#FF3C7FB1"/>
                                    <SolidColorBrush x:Key="CircleFillHighlightBrush" Color="Transparent"/>
                                    <SolidColorBrush x:Key="ArrowStrokeHighlightBrush" Color="#222"/>
                                    <SolidColorBrush x:Key="CircleFillBrush" Color="Transparent"/>
                                    <SolidColorBrush x:Key="StrokeBrush" Color="DarkGray"/>
                                    <SolidColorBrush x:Key="ArrowStrokeBrush" Color="#666"/>
                                </CheckBox.Resources>
                                <CheckBox.Template>
                                    <ControlTemplate TargetType="{x:Type CheckBox}">
                                        <Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" BorderThickness="1,0,1,0"  BorderBrush="{StaticResource PA_DarkGray}">
                                            <Grid x:Name="CheckBoxButtonGrid"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                                                <Ellipse x:Name="circle"  Fill="{StaticResource CircleFillBrush}" HorizontalAlignment="Center" Height="19" Width="19" 
                                                                 Stroke="{StaticResource StrokeBrush}" VerticalAlignment="Center" />
                                                <Path x:Name="arrow"  HorizontalAlignment="Center" SnapsToDevicePixels="false" 
                                                              Stroke="{StaticResource ArrowStrokeBrush}" StrokeThickness="2" VerticalAlignment="Center"/>
                                            </Grid>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsChecked" Value="true">
                                                <Setter Property="Data" TargetName="arrow" Value="M 1,4.5  L 4.5,1  L 8,4.5"/>
                                            </Trigger>
                                            <Trigger Property="IsChecked" Value="false">
                                                <Setter Property="Data" TargetName="arrow" Value="M 1,1.5 L 4.5,5 L 8,1.5"/>
                                            </Trigger>
                                            <Trigger Property="IsMouseOver" Value="true">
                                                <Setter Property="Stroke" TargetName="circle" Value="{StaticResource CircleStrokeHighlightBrush}"/>
                                                <Setter Property="Fill" TargetName="circle" Value="{StaticResource CircleFillHighlightBrush}"/>
                                                <Setter Property="Stroke" TargetName="arrow" Value="{StaticResource ArrowStrokeHighlightBrush}"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </CheckBox.Template>
                                <CheckBox.FocusVisualStyle>
                                    <Style>
                                        <Setter Property="Control.Template">
                                            <Setter.Value>
                                                <ControlTemplate>
                                                    <Border>
                                                        <Rectangle Margin="0" SnapsToDevicePixels="true" Stroke="Black" StrokeThickness="1" StrokeDashArray="1 2"/>
                                                    </Border>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </CheckBox.FocusVisualStyle>
                            </CheckBox>

此视图,我在应用程序的弹出窗口中显示。 一切工作正常,但是如果我将弹出窗口保持打开状态15至20分钟(在CollpasedView模式下),则CheckBox不会检查和取消选中,并且用于更新复选框箭头数据的触发器不会在UI中更新。 (在Snoop中,IsChecked属性正在更新,但在UI中,CheckBox模板未更新) 请帮助解决问题。

0 个答案:

没有答案