listbox wpf 取消边框_停止使用箭头C#WPF导航列表框(Stop listbox from navigating with arrows C# WPF)...
停止使用箭頭C#WPF導航列表框(Stop listbox from navigating with arrows C# WPF)
我有一個畫布,可以使用箭頭鍵移動元素,但是當我在列表框中選擇當前在畫布上的元素時。 向下箭頭鍵將向下篩選列表,直到它到達底部,然后將在畫布上移動元素。 另一個問題是它會將元素移動到現在選中的列表框的最底部。
I have a canvas which elements can be moved with the arrow keys, however when i select an element in a listbox that is currently on the canvas. The arrow key down will filter down the list until it reaches the bottom then will move the element on the canvas. the other problem is it will then move the element at the very bottom of the listbox that is now selected.
原文:https://stackoverflow.com/questions/42110770
更新時間:2020-10-11 12:10
最滿意答案
您可以處理ListBox的PreviewKeyDown事件:
1
2
3
private void lb_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down || e.Key == Key.Up)
e.Handled = true;
}
You could handle the PreviewKeyDown event for the ListBox:
1
2
3
private void lb_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down || e.Key == Key.Up)
e.Handled = true;
}
2017-02-08
相關問答
看看這個問題。 如何使用TwoWay模式將Listview SelectedItem綁定到文本框? 在你的情況下使用
HorizontalAlignment="Left"
Margin="265,148,0,0"
Name="textBox1"
VerticalAlignment="Top" Width="198"
Text="{Binding SelectedItem.Name, ElementName=listBox1}"
...
您可以處理要覆蓋的控件的KeyDown事件。 例如, private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
//execute go button method
GoButtonMethod();
//or if it's an event handler (should be a method)
...
答案是改變更新中的foreach循環 resultsbox.ItemsSource = results;
if (results.Count == 0)
{
foreach (ele item in eles)
{
if (!results.Contains(item.nameElement))
{
results.Add(item.nameElement);
...
有一個如何根據推薦的MVVM設計模式實現這種級聯ComboBox的示例: https : //blog.magnusmontin.net/2013/06/17/cascading-comboboxes-in-wpf-using-mvvm/ 您可以將第一個ListBox的SelectedItem屬性綁定到視圖模型的source屬性。 在這個的setter中,然后設置另一個集合屬性,將第二個ListBox的ItemsSource屬性綁定到,例如:
您添加具有這些屬性的項目,例如匿名對象 : myList.Items.Add(new { Id = "Lorem", ..
...
FoodInformation類不包含屬性: Image和Name (您正嘗試在DataTemplate綁定這些屬性)。 從代碼隱藏中我們可以創建具有屬性Dinner和DinnerImage的FoodInformation類的定義: class FoodInformation
{
public string Dinner { get; set; }
public ImageSource DinnerImage { get; set; }
}
所以你應該綁定屬性Dinner和Din
...
您可以處理ListBox的PreviewKeyDown事件:
1
2
3
private void lb_PreviewKeyDown(object sender, KeyEve
...
GroupModelList/Name在此處不是有效的屬性路徑。 像這樣設置不會使ListBox顯示GroupModelList集合中數據項的Name屬性。 您將不得不設置ListBox的DisplayMemberPath屬性:
DisplayMemberPath="Name"/>
或設置ItemTempl
...
for (int i = 0; i < listBox.Items.Count; i++)
{
var item = listBox.ItemContainerGenerator.ContainerFromItem(listBox.Items[i]) as ListBoxItem;
var template = item.ContentTemplate as DataTemplate;
ContentPres
...
總結
以上是生活随笔為你收集整理的listbox wpf 取消边框_停止使用箭头C#WPF导航列表框(Stop listbox from navigating with arrows C# WPF)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 『Golang』Martini框架入门
- 下一篇: c# char unsigned_dll