【发布时间】:2016-08-01 14:21:54
【问题描述】:
我有以下ListBox:
<ListBox x:Name="SequencesFilesListBox" ItemsSource="{Binding SequencesFiles, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="DarkBlue" BorderBrush="Transparent" />
定义为ItemsSource 的SequencesFiles 是ObservableCollection<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);
}
是否可以在双击而不是单击时调用Command(PlaylistLoadCommand)?
【问题讨论】:
-
我正在手动将新按钮添加到集合中... 好吧,这就是你的问题。您可能会以更简单的方式实现您的目标。您可能想回顾一下为什么您要这样做,并可能要求一种更好、更 mvvm/wpf-ish 的方式来实现您的目标。在另一个问题中。
-
你能给我的答案投票吗(徽章和东西)?
标签: c# wpf mvvm command behavior