2

我的用户控件在 itemscontrol 中包含 3000 个 NewDotControls。NewDotControl 的 ControlTemplate 在定义视觉状态的样式中指定,并且有一个事件触发器在 Loaded 事件上调用 GotoStateAction。

<Controls:NewDotControl Style="{StaticResource MyDotStyle}"/>

3000 个 NewDotControls 中只有大约 445 个进入 EventTrigger 定义的“选定”状态,而其余的 NewDotControls则没有。当我使用绑定到 ViewModel 的 DataTriggers 时也会发生同样的情况。相同的 xaml/code/app 在 WPF 中工作。

<Style x:Key="MyDotStyle" TargetType="Control">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Control">
                        <Viewbox x:Name="viewbox" RenderTransformOrigin="0.5,0.5"
                                 >
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="UnSelected">
                                    </VisualState>
                                    <VisualState x:Name="Selected">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="InnerEllipse" d:IsOptimized="True">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="2"/>
                                                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Loaded">
                                    <ei:GoToStateAction StateName="Selected"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                            <Ellipse x:Name="InnerEllipse" Stroke="Red" StrokeThickness="0" RenderTransformOrigin="0.5,0.5"/>
                        </Viewbox>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

为什么 DataTriggers/EventTriggers/GotoStateAction 不适用于 ItemsControl 中的所有控件?

如果我删除初始加载的 EventTrigger,大约 775 到 800 个 NewDotControls 响应 DataTriggers/GotoStateAction。如果我将命令连接到控件,命令会执行并修改 ViewModel 属性并触发 PropertyChanged 事件,但 DataTrigger/GotoStateAction 仍然不会发生。

我会错过什么?项目控件中可以数据绑定的项目数量是否有限制?或者是否存在问题,因为它在 ControlTemplate 中?为什么这在 WPF 中有效,但在 Silverlight 中无效?

谢谢!!!拉杰什

4

0 回答 0