2013-06-25 11 views
0

J'essaye d'utiliser un eventToCommand pour déterminer quand l'utilisateur se lève sur un contrôle de curseur. Cependant, il ne se fait jamais virer. Ceci est contenu dans un modèle de donnéesEventToCommand ne se déclenche pas

<DataTemplate x:Key="RunEventsTemplate"> 
    <di:DIGroupBox Grid.Row="2" Header="Real-Time Modifications" DataContext="{Binding DataContext.ScenarioHelper.EventPlayingService,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}}" > 
     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto" /> 
       <RowDefinition /> 
       <RowDefinition /> 
       <RowDefinition /> 
      </Grid.RowDefinitions> 
      <di:DIGroupBox Header="Audio" DataContext="{Binding CurrentAudioEvent}"> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition /> 
         <RowDefinition /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="Auto" /> 
         <ColumnDefinition /> 
        </Grid.ColumnDefinitions> 
        <di:DILabel Content="Filename: " /> 
        <di:DIComboBox Grid.Column="1" /> 
        <di:DICheckBox Grid.Row="1">Loop Audio File?</di:DICheckBox> 
        <di:DIImageToggleButton Grid.Row="1" Grid.Column="1" Height="23" Width="23" HorizontalAlignment="Left" Image="PlayIcon_White"></di:DIImageToggleButton> 
       </Grid> 
      </di:DIGroupBox> 
      <di:DIGroupBox Grid.Row="1" Header="Odors"> 
       <ItemsControl ItemsSource="{Binding VehicleOdors}" ItemTemplate="{StaticResource ScentTemplate}"> 
        <ItemsControl.ItemsPanel> 
         <ItemsPanelTemplate> 
          <WrapPanel></WrapPanel> 
         </ItemsPanelTemplate> 
        </ItemsControl.ItemsPanel> 
       </ItemsControl> 
      </di:DIGroupBox> 
      <di:DIGroupBox Grid.Row="2" Header="Lighting" DataContext="{Binding CurrentLightingEvent}"> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition /> 
         <RowDefinition /> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width=".3*" /> 
         <ColumnDefinition /> 
        </Grid.ColumnDefinitions> 
        <di:DILabel Content="Color: " /> 
        <di:DILabel Grid.Row="1" Content="Strobe: " /> 
        <StackPanel Grid.Column="1" Orientation="Horizontal"> 
         <di:DIRadioButton DIRadioButtonStyle="ToggleButton" IsChecked="{Binding CurrentDMXLightColor,Converter={StaticResource enumConverter},ConverterParameter={x:Null}}" Content="Off" Margin="0,0,5,0" Height="23" Width="50"></di:DIRadioButton> 
         <di:DIRadioButton DIRadioButtonStyle="ToggleButton" IsChecked="{Binding CurrentDMXLightColor,Converter={StaticResource enumConverter},ConverterParameter=White}" Content="White" Margin="0,0,5,0" Height="23" Width="50" /> 
         <di:DIRadioButton DIRadioButtonStyle="ToggleButton" IsChecked="{Binding CurrentDMXLightColor,Converter={StaticResource enumConverter},ConverterParameter=Red}" Content="Red" Margin="0,0,5,0" Height="23" Width="50"/> 
         <di:DIRadioButton DIRadioButtonStyle="ToggleButton" IsChecked="{Binding CurrentDMXLightColor,Converter={StaticResource enumConverter},ConverterParameter=Blue}" Content="Blue" Height="23" Width="50"/> 
        </StackPanel> 
        <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center"> 
         <TextBlock Text="Always On" Foreground="White" VerticalAlignment="Center" TextWrapping="Wrap" MaxWidth="50" Margin="0,0,5,0" /> 
         <di:DISlider Minimum="0" Maximum="100" Value="{Binding StrobeRate}" > 
          <i:Interaction.Triggers> 
           <i:EventTrigger EventName="MouseUp"> 
             <cmd:EventToCommand Command="{Binding UserChangedSliderValueCommand}"></cmd:EventToCommand> 
           </i:EventTrigger> 
          </i:Interaction.Triggers> 
         </di:DISlider> 
         <TextBlock Text="Fast Strobe" Foreground="White" VerticalAlignment="Center" TextWrapping="Wrap" MaxWidth="50" /> 
        </StackPanel> 
       </Grid> 
      </di:DIGroupBox> 
      <di:DIGroupBox Header="Smoke" Grid.Row="3" DataContext="{Binding CurrentSmokeEvent}"> 
       <Grid> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="60" /> 
         <ColumnDefinition Width="Auto" /> 
         <ColumnDefinition /> 
        </Grid.ColumnDefinitions> 
        <di:DIToggleButton Content="Off" Width="50" Height="23"> 
         </di:DIToggleButton> 
        <di:DILabel Grid.Column="1" Content="Intensity:" Margin="10,0,0,0" /> 
        <di:DISlider Grid.Column="2" VerticalAlignment="Center" Value="{Binding Intensity}" Minimum="0" Maximum="100" > 

        </di:DISlider> 
       </Grid> 
      </di:DIGroupBox> 
     </Grid> 
    </di:DIGroupBox> 
</DataTemplate> 

La commande ressemble à ceci

private RelayCommand userChangedSliderValueCommand; 
    public RelayCommand UserChangedSliderValueCommand 
    { 
     get 
     { 
      return userChangedSliderValueCommand = (userChangedSliderValueCommand??new RelayCommand(() => 
       { 
        LightingEvent newLe = new LightingEvent(); 
        newLe.DMXLightColor = CurrentDMXLightColor; 
        newLe.StrobeRate = StrobeRate; 
        UserAddNewEvent(newLe); 
       } 
       )); 
     } 
    } 

Je mets un point de rupture et il ne fait jamais touché. J'utilise .net 4.5

+0

Voyez-vous des erreurs de liaison dans votre fenêtre de sortie? –

+0

essayez d'utiliser au lieu de Krish

+0

Tout d'abord, vérifiez si l'événement "MouseUp" est correctement déclenché car il s'agit d'un contrôle tiers. Ensuite, comme Krish l'a suggéré, essayez InvokeCommandAction. Si cela ne fonctionne toujours pas, vérifiez votre liaison. –

Répondre

0

Vous ne savez pas si votre DISlider peut le faire en tant que curseur WPF standard, mais vous pouvez essayer. Tout d'abord, vous devez obtenir l'objet de pouce du curseur, reportez-vous à Get the Thumb of a Slider:

private static Thumb GetThumb(Slider slider) 
{ 
    var track = slider.Template.FindName("PART_Track", slider) as Track; 
    return track == null ? null : track.Thumb; 
} 

Ensuite, vous écoutez l'événement DragCompleted de pouce, un exemple dans mon projet:

#region Manage Deferred Scrolling 

    void VerticalScrollBarLoaded(object sender, RoutedEventArgs e) 
    { 
     VerticalScrollBar.Track.Thumb.DragStarted -= ThumbDragStarted; 
     VerticalScrollBar.Track.Thumb.DragCompleted -= ThumbDragCompleted; 
     VerticalScrollBar.Track.Thumb.DragStarted += ThumbDragStarted; 
     VerticalScrollBar.Track.Thumb.DragCompleted += ThumbDragCompleted; 
    } 

    void ThumbDragCompleted(object sender, DragCompletedEventArgs e) 
    { 
     IsDeferredScrolling = false; 
     if (CancelSelectionCrossingPage) 
      SelectionSettings.SelectedCells.Clear(); 
    } 

    void ThumbDragStarted(object sender, DragStartedEventArgs e) 
    { 
     IsDeferredScrolling = true; 
    } 

    #endregion 

En outre, vous pouvez envisager de liaison votre valeur de curseur. Je pense que ça devrait être un meilleur moyen. Si c'est difficile, vous pouvez hériter de votre contrôle et ajouter une propriété de dépendance pour y parvenir.

+0

Alors, où irait cette fonction privée? Est-ce que je ferais un curseur personnalisé? – joshwl2003

+0

Dans votre code derrière où peut voir le contrôle DISlider. Si votre datatemplate est dans un dictionnaire de ressources et qu'il est difficile d'avoir du code, vous pouvez mettre le code ci-dessus dans un comportement et utiliser le comportement pour gérer ces événements ou vous pouvez écrire un contrôle personnalisé héritant DISlider, y mettre du code et utiliser dans votre datatemplate. –

+0

Merci pour l'aide. Il s'avère que vous ne pouvez pas vous lier à un événement routé en utilisant le déclencheur d'événement interactions normal. Vous devez faire votre propre place. J'ai trouvé le blog suivant pour l'expliquer http://joyfulwpf.blogspot.com/2009/05/mvvm-invoking-command-on-attached-event.html – joshwl2003