Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF item.Content.ToString()/ListBox代码_C#_Wpf - Fatal编程技术网

C# WPF item.Content.ToString()/ListBox代码

C# WPF item.Content.ToString()/ListBox代码,c#,wpf,C#,Wpf,我是c#和WPF的新手,ListBoxItem.Contentproperty有问题: ListBoxItem itm = new ListBoxItem(); itm.Content = "klant aantalConsumpties"; listBoxOverzicht.Items.Add(itm); 我做错了什么? 这是我的密码: foreach (var item in listBoxOverzicht.Items) { if (item.ToString().Conta

我是c#和WPF的新手,
ListBoxItem.Content
property有问题:

ListBoxItem itm = new ListBoxItem();
itm.Content = "klant aantalConsumpties";
listBoxOverzicht.Items.Add(itm);
我做错了什么? 这是我的密码:

foreach (var item in listBoxOverzicht.Items)
{ 
     if (item.ToString().Contains(klant))                       
     { 
          MessageBoxResult result= MessageBox.Show("Er is reeds een klant met als naam " + item.Content.ToString() + ".\n" +
           "Klik op JA als je de consumpties "+
           "wilt toevoegen aan deze klant.\n" + 
           "Klik op NEE als je het om nieuwe klant gaat.\n"+
           "Klik Annuleren om input te wijzigen.","Opdracht 2", 
            MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);

          switch (result)
          { 
               case etc....
我无法使用
item.Content.ToString()
,因为我收到以下消息:

“对象”不包含“内容”的定义,也没有扩展名 无法找到接受类型为“object”的第一个参数的方法(是 u缺少使用指令或组件引用?)


只需删除
内容
ToString()
就足够了:

item.ToString()
如果只需要特定属性,请尝试以下操作:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());
最后,在您的情况下,因为您需要
ListBoxItem
Content
属性,所以您应该尝试以下方法:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());

只需删除
内容
ToString()
就足够了:

item.ToString()
如果只需要特定属性,请尝试以下操作:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());
最后,在您的情况下,因为您需要
ListBoxItem
Content
属性,所以您应该尝试以下方法:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());

只需删除
内容
ToString()
就足够了:

item.ToString()
如果只需要特定属性,请尝试以下操作:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());
最后,在您的情况下,因为您需要
ListBoxItem
Content
属性,所以您应该尝试以下方法:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());

只需删除
内容
ToString()
就足够了:

item.ToString()
如果只需要特定属性,请尝试以下操作:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());
最后,在您的情况下,因为您需要
ListBoxItem
Content
属性,所以您应该尝试以下方法:

MessageBox.Show((item as Model).Name.ToString());
MessageBox.Show((item as ListBoxItem).Content.ToString());

您可以尝试简单地使用item.ToString()而不是假设它是一个简单的文本列表框项


如果要显示更复杂的对象,则可以强制转换到该对象并显示相应的特性

您可以尝试使用simply item.ToString()代替简单的文本列表框项


如果要显示更复杂的对象,则可以强制转换到该对象并显示相应的特性

您可以尝试使用simply item.ToString()代替简单的文本列表框项


如果要显示更复杂的对象,则可以强制转换到该对象并显示相应的特性

您可以尝试使用simply item.ToString()代替简单的文本列表框项


如果要显示更复杂的对象,则可以强制转换到该对象并显示相应的特性

范塔斯蒂克。非常感谢!现在效果很好!范塔斯蒂克。非常感谢!现在效果很好!范塔斯蒂克。非常感谢!现在效果很好!范塔斯蒂克。非常感谢!现在效果很好!