gpt4 book ai didi

c - XAML、列表框、列表框项目

转载 作者:行者123 更新时间:2023-11-30 16:27:00 25 4
gpt4 key购买 nike

我正在尝试获取有关鼠标单击事件的数据。在 item.content 中,我看到了必要的数据,但它没有获取它们。我需要获取这个对象的值...但我不知道如何获取。我将非常感谢您的建议或帮助。

public partial class MainWindow : Window
{
class Room_List
{
public string Name { get; set; }
public string IP { get; set; }
public string Status { get; set; }
public string other { get; set; }
public Room_List() { }
public Room_List(string name, string ip, string status)
{
Name = name;
IP = ip;
Status = status;
}
}

ObservableCollection<Room_List> data_room_list = new ObservableCollection<Room_List>();
/*ObservableCollection<Conference_Room> data_conference_room = new ObservableCollection<Conference_Room>();*/

public MainWindow()
{
InitializeComponent();
//this.DataContext = this;
listbox_room_list.ItemsSource = data_room_list;

//входные тестовые данные
data_room_list.Add(new Room_List("Переговорная 101", "10.45.130.1", "fsdf"));
data_room_list.Add(new Room_List("Переговорная 102", "10.45.130.2", "fs12df"));
data_room_list.Add(new Room_List("Переговорная 103", "10.45.130.3", "fsf21df"));
data_room_list.Add(new Room_List("Переговорная 104", "10.45.130.4", "fsderf"));
data_room_list.Add(new Room_List("Переговорная 105", "10.45.130.5", "fsagsddf"));
}
private void PlaceholdersListBox_OnPreviewMouseDown2(object sender, MouseButtonEventArgs e)
{
var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;
if (item != null)
{
// ListBox item clicked - do some cool things here
} }
private void listBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string str = listbox_room_list.SelectedValue.ToString();
} } }

最佳答案

这很容易...但不适合我,有人提示我:) Room_List room_List = (Room_List)Item.Content;

关于c - XAML、列表框、列表框项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52913588/

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