2010-01-03 6 views
1

데이터 형식을 사용하는 목록 상자가 있습니다. 내가 필요한 것은 항목을 선택한 후에하는 방법입니다. 내부의 목록 항목이 아닌 목록 상자 자체를 축소하려고합니다. selector.selected 및 unselected에 대해 eventtrigger를 시도했지만 실행하지 않습니다. datatemplate에 datatrigger를 넣었지만 여기에서 목록 상자에 액세스 할 수 없습니다. 어떤 아이디어?항목 선택시 목록 상자 축소

답변

1

이것은 약간 간접적 인 해결책이지만, ListBox 자체에 DataTrigger를 넣고 SelectedItems.Count에 바인딩하여 처리 할 수 ​​있습니다. ListBox의 기본값을 "더 작은"모양으로 지정해야합니다. 그런 다음 트리거는 SelectedItems.Count가 0인지 확인하고, 그렇다면 ListBox를 으로 만들어야합니다.. 다음 예제에서는 간단히 ListBox.Background를 설정했지만 LayoutTransform 또는 RenderTransform 또는 Width/Height 또는 ListBox를 "축소"하는 데 사용하도록이 컨트롤을 적용 할 수 있어야합니다.

<ListBox.Style> 
    <Style TargetType="ListBox"> 
    <Style.Triggers> 
     <DataTrigger Binding="{Binding SelectedItems.Count, RelativeSource={RelativeSource Self}}" Value="0"> 
     <Setter Property="Background" Value="Orange" /> 
     </DataTrigger> 
    </Style.Triggers> 
    </Style> 
</ListBox.Style> 

분명히이 옵션을 선택하면 전체 ListBox가 축소됩니다 (또는 단순화 된 예제에서는 흰색으로 바뀝니다). 선택한 ListBoxItem을 전체 크기로 유지하려면 ListBox.ItemContainerStyle을 사용하십시오. 이 경우 IsSelected에서 트리거하고 적절한 축소기를 적용하여 '축소'변환을 되돌릴 수 있습니다. 음수 여백을 적용하거나 역 스케일 변환을 적용합니다. (A 일반 트리거는이를 위해 할 것입니다.) 모든

0

첫째, 올바른 이벤트 둘째, 당신은 창 수준에서 Storyboard를 사용할 수 SelectionChanged하지 Selected되는 후크하려면 다음 Storyboard

:

<Storyboard x:Key="Storyboard1"> 
    <DoubleAnimationUsingKeyFrames 
     BeginTime="00:00:00" 
     Storyboard.TargetName="grid" 
     Storyboard.TargetProperty="(FrameworkElement.Height)"> 
     <SplineDoubleKeyFrame KeyTime="00:00:00.5000000" Value="0"/> 
    </DoubleAnimationUsingKeyFrames> 
</Storyboard> 

윈도우 트리거 :

<Window.Triggers> 
    <EventTrigger RoutedEvent="Selector.SelectionChanged" SourceName="listBox"> 
     <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/> 
    </EventTrigger> 
</Window.Triggers> 

그리고 약간의 용 장식과 ListBox (효과를 위해 ons) :

<Border 
    BorderThickness="2" 
    CornerRadius="3" 
    BorderBrush="#FF000000" 
    Padding="3" 
    VerticalAlignment="Top"> 
    <Grid Height="200" x:Name="grid"> 
     <ListBox x:Name="listBox" Height="200"> 
      <ListBoxItem Content="ListBoxItem"/> 
      <ListBoxItem Content="ListBoxItem"/> 
      <ListBoxItem Content="ListBoxItem"/> 
      <ListBoxItem Content="ListBoxItem"/> 
     </ListBox> 
    </Grid> 
</Border> 
관련 문제