如何通过C#以编程方式知道列表选择器中选择的菜单。 [英] How to know what menu is selected in the list picker by C# programmatically.?
问题描述
嗯,这是
我的应用程序中有`listpicker`。我从`Data Binding`中显示了`listpicker`的菜单项。
$
我现在需要通过c#编程来查看`ListPicker`中的菜单项。例如,`CategoriesList`是我为这个`ListPicker`创建的Binding。在`CategoriesList`中,我有`Bank`,`Email`,`Personal`和`Gadgets`。这些是listpicker的菜单项
。
如何通过C#以编程方式知道列表选择器中选择的菜单。
XAML代码:
< toolkit:ListPicker
X:名称= QUOT; categoriesListPicker"
ItemsSource =" {Binding CategoriesList}"
DisplayMemberPath =" Name">
C#代码失败;
var list = categoriesListPicker.Text;
开关(清单)
{
case" Bank":
// ..做一些事情
case" Email":
//。做某事
case" Personal":
// ..做点什么
}
它失败了。错误:
$
'Microsoft.Phone.Controls.ListPicker'不包含'Text'的定义,也没有扩展名方法'Text'
接受类型为'Microsoft.Phone.Controls.ListPicker'的第一个参数可以找到
(你是否缺少using指令或汇编引用?)
- Mohamed Thaufeeq A
你可以用
categoriesListPicker.SelectedItem <获取所选对象/ pre>
你必须从模型中转换对象,如
CategoryListType obj = categoriesListPicker.SelectedItem as CategoryListType;
if(obj!= null)
{
//用你的对象做一些事情
Messagebox.show(obj.Bank);
}
希望这会有所帮助。
Well,
I have `listpicker` in my app. I have shown the menu items for the `listpicker` from `Data Binding`.
I need to what menu item is in the `ListPicker` right now, by c# programmatically. For Example, `CategoriesList` is the Binding I have created for this `ListPicker`. In `CategoriesList`, I have `Bank`, `Email`, `Personal` and `Gadgets`. These are the menu items
for the listpicker.
How to know what menu is selected in the list picker by C# programmatically.
XAML CODE:
<toolkit:ListPicker x:Name="categoriesListPicker" ItemsSource="{Binding CategoriesList}" DisplayMemberPath="Name">
Failed C# Code;
var list = categoriesListPicker.Text; switch(list) { case "Bank": //.. do something case "Email": //.. do something case "Personal": //.. do something }
It fails. Error:
'Microsoft.Phone.Controls.ListPicker' does not contain a definition for 'Text' and no extension method 'Text'
accepting a first argument of type 'Microsoft.Phone.Controls.ListPicker' could be found
(are you missing a using directive or an assembly reference?)
- Mohamed Thaufeeq A
Hi,
you can get the selected object with
categoriesListPicker.SelectedItemYou have to cast the object from your model like
CategoryListType obj = categoriesListPicker.SelectedItem as CategoryListType; if(obj != null) { // do something with your object Messagebox.show(obj.Bank); }
Hope this helps.
这篇关于如何通过C#以编程方式知道列表选择器中选择的菜单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!