gpt4 book ai didi

c# - 以编程方式单击 ContentDialog 的 PrimaryButton

转载 作者:太空宇宙 更新时间:2023-11-03 20:56:21 25 4
gpt4 key购买 nike

在 UWP 中,当文本框的 KeyDown 事件检测到已按下 Enter 时,如何以编程方式单击 ContentDialog 的 PrimaryButton?只是尝试添加键盘快捷键以在文本框中接受答案并从键盘关闭所有对话框,而无需移动鼠标并单击确定。

private void A1TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
// Programmatically Click PrimaryButton Here
}
}

<ContentDialog
x:Class="App1.ContentDialog1"
Title="DialogBox"
Loaded="ContentDialog_Loaded"
PrimaryButtonText="Ok"
SecondaryButtonText="Cancel"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick">

<Grid Name="A1Grid">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox Name="A1TextBox" Grid.Row="0"
PlaceholderText="Search String"
TextChanged="A1TextBox_TextChanged"
KeyDown="A1TextBox_KeyDown"/>
<ScrollViewer Grid.Row="1"
ScrollViewer.VerticalScrollBarVisibility="Auto"
VerticalAlignment="Stretch">
<ListBox Name="A1ListBox" MinHeight="200"/>
</ScrollViewer>
</Grid>
</ContentDialog>

最佳答案

使用以下代码:

RoutedEventArgs f;

private void A1TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter)
{
ContentDialog_PrimaryButtonClick (Sender, f);
}
}

然后他将触发 PrimaryButtonClick 事件。

关于c# - 以编程方式单击 ContentDialog 的 PrimaryButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50204115/

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