2016-04-11 19 views
0

WPFのコマンドをダブルクリックしますプログラムでバインドボタンは、私が<code>ListBox</code>次いる

<ListBox x:Name="SequencesFilesListBox" ItemsSource="{Binding SequencesFiles, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="DarkBlue" BorderBrush="Transparent" /> 

SequencesFilesItemsSourceObservableCollection<Button>であると定義します。

私は手動で次の関数を使用してコレクションに新しいButtonsを追加している:

private void AddSequenceToPlaylist(string currentSequence) 
{ 
    if (SequencesFiles.Any(currentFile => currentFile.ToolTip == currentSequence)) return; 

    var newSequence = new Button 
    { 
     ToolTip = currentSequence, 
     Background = Brushes.Transparent, 
     BorderThickness = new Thickness(0), 
     HorizontalAlignment = HorizontalAlignment.Stretch, 
     HorizontalContentAlignment = HorizontalAlignment.Stretch, 
     Content = Path.GetFileName(currentSequence), 
     Command = PlaylistLoadCommand, 
     CommandParameter = currentSequence, 
    }; 
    SequencesFiles.Add(newSequence); 
} 

は、クリック時にクリック、ダブル、いない時にCommandPlaylistLoadCommand)を呼び出すことが可能ですか?

+0

をあなたのコマンドを起動するためにあなたのButtonInputBindingを設定し、私は手動でコレクションに新しいボタンを追加している... *さて、あなたの問題があります。あなたはおそらくより簡単な方法であなたの目標を達成することができます。あなたは*なぜあなたがこれをやっているのか見直したいかもしれませんが、あなたの目標を達成するためのより良い、より多くのmvvm/wpf-ishの方法を尋ねるかもしれません。別の質問です。 – Will

+0

あなたは私の答えを投票できますか(バッジなど)? –

答えて

3

することができます*ダブルクリックで

var newSequence = new Button 
{ 
    ToolTip = currentSequence, 
    Background = Brushes.Transparent, 
    BorderThickness = new Thickness(0), 
    HorizontalAlignment = HorizontalAlignment.Stretch, 
    HorizontalContentAlignment = HorizontalAlignment.Stretch, 
    Content = Path.GetFileName(currentSequence), 
    CommandParameter = currentSequence, 
}; 

var mouseBinding = new MouseBinding(); 
mouseBinding.Gesture = new MouseGesture(MouseAction.LeftDoubleClick); 
mouseBinding.Command = PlaylistLoadCommand; 
newSequence.InputBindings.Add(mouseBinding); 
関連する問題