How to prevent the Key.Enter pressed event handled by ListBox with Avalonia 12.0.1?
#21197
-
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
|
I assume this is for source git? Can you point me to the source code snippet? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
You can just create an demo project that only contains a |
Beta Was this translation helpful? Give feedback.
-
|
You can register with code behind: <Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="TestApp.MainWindow"
Title="TestApp">
<ListBox Name="list" >
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 2</ListBoxItem>
<ListBoxItem>Item 3</ListBoxItem>
</ListBox>
</Window>
using Avalonia.Controls;
using Avalonia.Input;
namespace TestApp;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
list.AddHandler(KeyDownEvent, List_OnKeyDown, handledEventsToo: true);
}
private void List_OnKeyDown(object? sender, KeyEventArgs e)
{
throw new System.NotImplementedException();
}
}Notice the |
Beta Was this translation helpful? Give feedback.
-
|
My need is not only to capture the enter keydown event, but also to intercept the event, that is, I don't want the selection to be changed this matter.
|
Beta Was this translation helpful? Give feedback.

You can register with code behind: