0

私はこれを動作させるように努力しています。私はトランジションと少し苦労することを学ぶことを試みる。基本的には2つの行を含むグリッドで構成されたコンボボックスを作っています。一番上の行はボタンで、クリックすると一番下の行が開き、scrollviewerの動的に追加されたボタンが表示されます。クリックすると、下のグリッド行が折りたたまれます。wpf xamlのスクロールビューアから視覚的な状態を変更する方法

問題は、Clickイベントがスクロールビューア内で発生しないように見えるか、スコープなどでビジュアル状態が見つからないという問題です。 Button11をクリックするとSelectionModeがうまく動作しますが、項目ボタンをクリックしても何も起こりません。ボタンは、私がルーティングされたクリックイベントの火災問題なく行うことができますので、

Idはコードビハインド内の溶液に開くことが、私は

で運を持っていなかった、独自のカラーアニメーションや発火のイベントなどで完全に 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; 
    } 

答えて

0

をクリックしたときに何の例外/エラーだけで何も起こりません!!!

私はルート要素にvisualStateManagerを移動 - GRID1が、それはそれを

private void Button_Item_Click(object sender, RoutedEventArgs e) 
    { 
     bool g = ExtendedVisualStateManager.GoToElementState(this.Grid1 as FrameworkElement, "HiddenMode", true); 
    } 
に影響を与える場合、知りません
関連する問題