0

私はこれを機能させるために髪を引っ張っています。私はトランジションを行うことを学ぼうとしていて、少し苦労しています。基本的に、2行を含むグリッドで構成されるコンボボックスを作成しています。一番上の行はボタンで、クリックすると一番下の行が開きscrollviewer、動的に追加されたボタンが表示されます。クリックすると、一番下のグリッド行が折りたたまれます。

問題は、Click イベントがスクロール ビューアー内から発生していないように見えるか、スコープ内の視覚的な状態を見つけることができないことです。したがってSelectionMode、Button11 をクリックすると正常に動作しますが、アイテム ボタンをクリックしても何も起こりません。ボタンは、scrollviewer独自のカラーアニメーションや発火イベントなどで完全に機能します

ルーティングされたクリックイベントを問題なく発生させることができるので、コードビハインドの解決策を受け入れることができますが、運がありませんでした

VisualStateManager.GoToState(gridContent, "HiddenMode", true);

理想的には、これを追加できるカスタム ユーザー コントロールにしたいlocal:CustomComboBoxのですが、この段階では、カスタム コントロールのコントロール内にコントロールを持つことは複雑です。

MyButton1シンプルなボタンですが、色の変化などがあります

例外/エラーはありません。ボタンをクリックしても何も起こりません

<Window.Resources>

    <Storyboard x:Key="sb1">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="gridContent" Storyboard.TargetProperty="Height">
            <EasingDoubleKeyFrame KeyTime="0" Value="30" />
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="160" />
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="scrItems" Storyboard.TargetProperty="Height">
            <EasingDoubleKeyFrame KeyTime="0" Value="0" />
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="130" />
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
    <Storyboard x:Key="sb2">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="gridContent" Storyboard.TargetProperty="Height">
            <EasingDoubleKeyFrame KeyTime="0" Value="160" />
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="30" />
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetName="scrItems" Storyboard.TargetProperty="Height">
            <EasingDoubleKeyFrame KeyTime="0" Value="130" />
            <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" />
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Window.Resources>


<Grid Name="Grid1" Margin="0,22,0,0" RenderTransformOrigin="0.5,0.5">
        <Grid Name="gridContent" HorizontalAlignment="Left" Margin="187,74,0,0" VerticalAlignment="Top" Width="140" Height="30" RenderTransformOrigin="0.5,0.5">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="SelectionMode" Storyboard="{StaticResource sb1}" />
                <VisualState x:Name="HiddenMode" Storyboard="{StaticResource sb2}" />
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.RowDefinitions>
                <RowDefinition Height="30"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>


        <local1:Button1 Name="Button11" Content="Click" Height="30" Grid.Row="0" Margin="0,0,0,30">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <ei:GoToStateAction TargetName="gridContent" StateName="SelectionMode" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </local1:Button1>
        <ScrollViewer Name="scrItems"  VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden" Margin="0" Width="140" Height="0" Grid.Row="1">

            <ItemsControl x:Name="stkItems">

                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical"/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>

                        <local1:Button1 Content="Click" Height="30">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">

                                    <ei:GoToStateAction TargetName="gridContent" StateName="HiddenMode" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </local1:Button1>
                    </DataTemplate>

                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </Grid>
</Grid>




private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        lstItems = new ObservableCollection<MyButton.Button1>();
        for (int i = 0; i <= 999; i++)
        {
            MyButton.Button1 item1 = new Button1();
            item1.Content = "Item " + i;
            item1.Width = stkItems.Width;
            item1.Height = 30;
            //item1.Click += new RoutedEventHandler(Button_Item_Click);
            lstItems.Add(item1);
        }
        stkItems.DataContext = this.stkItems;
        stkItems.ItemsSource = lstItems;
    }
4

1 に答える 1