gpt4 book ai didi

c# - 以编程方式将按钮绑定(bind)到双击命令 wpf

转载 作者:行者123 更新时间:2023-12-03 10:57:51 24 4
gpt4 key购买 nike

我有以下 ListBox :

<ListBox x:Name="SequencesFilesListBox" ItemsSource="{Binding SequencesFiles, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Foreground="DarkBlue" BorderBrush="Transparent" />
SequencesFiles定义为 ItemsSourceObservableCollection<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 ) 双击而不是单击?

最佳答案

您可以设置InputBinding给您的Button双击触发你的命令

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);

关于c# - 以编程方式将按钮绑定(bind)到双击命令 wpf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36548413/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com