2010-09-23 141 views
0

如果用戶沒有做出選擇,我有一個組合框將保持打開狀態。我想用觸發器在2秒後關閉組合框。下面是包括實現這個我沒eventtrigger嘗試我的組合框風格的部分:n秒後關閉組合框

<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}"> 
    <Setter Property="FontFamily" Value="Bryant"/> 
    <Setter Property="FontSize" Value="18px"/> 
    <Setter Property="FontWeight" Value="Bold"/> 
    <Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/> 
    <Setter Property="Foreground" Value="#FF000000"/> 
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/> 
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/> 
    <Setter Property="Padding" Value="4,3"/> 
    <Setter Property="Margin" Value="5"/> 
    <Setter Property="Template"> 
    <Setter.Value> 
    <ControlTemplate TargetType="{x:Type ComboBox}"> 
     <Grid x:Name="MainGrid" SnapsToDevicePixels="true"> 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="0*"/> 
     <ColumnDefinition/> 
     <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/> 
     </Grid.ColumnDefinitions> 
     <Popup Margin="1" x:Name="PART_Popup" AllowsTransparency="true" StaysOpen="False" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Grid.ColumnSpan="2" Grid.Column="1"> 
     <Border x:Name="DropDownBorder" Background="{DynamicResource GrayBG}" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}" BorderBrush="{StaticResource GrayBGBorder}" BorderThickness="2,0,2,2" CornerRadius="0,0,4,4" Width="{Binding ActualWidth, ElementName=DropWidth}"> 
     <ScrollViewer CanContentScroll="true" Template="{DynamicResource NeeboScrollViewer}"> 
      <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/> 
     </ScrollViewer> 
     </Border> 
     </Popup> 
     <ToggleButton x:Name="DropWidth" Style="{StaticResource ComboBoxReadonlyToggleButton}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Grid.Column="1"/> 
     <ContentPresenter HorizontalAlignment="Left" Margin="35,0,0,0" VerticalAlignment="Center" IsHitTestVisible="false" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Grid.Column="1"/> 
     </Grid> 
     <ControlTemplate.Triggers> 
     <Trigger Property="HasItems" Value="false"> 
     <Setter Property="Height" TargetName="DropDownBorder" Value="95"/> 
     </Trigger> 
     <Trigger Property="IsEnabled" Value="false"> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
     <Setter Property="Background" Value="#FFF4F4F4"/> 
     </Trigger> 
     <Trigger Property="IsGrouping" Value="true"> 
     <Setter Property="ScrollViewer.CanContentScroll" Value="false"/> 
     </Trigger> 
          <EventTrigger RoutedEvent="(Popup.Opened)" SourceName="PART_Popup" > 
           <BeginStoryboard> 
            <Storyboard> 
             <BooleanAnimationUsingKeyFrames Storyboard.TargetName="PART_Popup" Storyboard.TargetProperty="(Popup.IsOpen)"> 
              <DiscreteBooleanKeyFrame KeyTime="00:00:03" Value="False"/> 
             </BooleanAnimationUsingKeyFrames> 
            </Storyboard> 
           </BeginStoryboard> 
          </EventTrigger> 
         </ControlTemplate.Triggers> 
    </ControlTemplate> 
    </Setter.Value> 
    </Setter> 
    </Style> 

如何做到這一點有什麼建議?

回答

1

我不能想到這樣做沒有實現附加的行爲,將訂閱打開的事件,並等待2秒關閉它,如果不關閉已經。

如果你不知道什麼是附加行爲只是谷歌它。

執行完一個之後,您可以將其設置爲默認行爲。

+0

是的,這就是我需要的。得到它與一個附加的行爲工作。 Thansk! – 2010-09-24 20:18:48