Могу ли я получить VisualStateGroups, определенные в XAML, из кода в WPF? - PullRequest
0 голосов
/ 01 марта 2020

У меня есть код XAML, как показано ниже.

                <ControlTemplate TargetType="{x:Type local:ThumbnailItem}">
                    <ContentPresenter>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup Name="FocusedStates">
                                <VisualState Name="Selected">
                                    <Storyboard>
                                        <ColorAnimation To="Red" 
              Storyboard.TargetProperty="Background"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </ContentPresenter>
                </ControlTemplate>

Я хочу получить доступ к определенному VisualStateGroups из кода позади. Но приведенный ниже код VisualStateManager.GetVisualStateGroups всегда возвращает ноль.

 ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(this);
 var visualStateGroups = VisualStateManager.GetVisualStateGroups(myContentPresenter);

Есть ли какой-нибудь хороший способ добиться этого?

...