Microsoft.Phone.Controls.Toolkit ListPicker throws XamlParseException

北慕城南 提交于 2019-12-11 09:07:03

问题


After being advised that the native ComboBox was not the way to go I was told to look at the Silverlight Toolkit ListPicker. So I did and have got a problem.

I opened a new project and pulled a new ListPicker onto the MainPage. The ListPicker looks like:

<toolkit:ListPicker x:Name="Result">
    <toolkit:ListPickerItem Content="Win" />
    <toolkit:ListPickerItem Content="Place" />
    <toolkit:ListPickerItem Content="Lose" />
</toolkit:ListPicker>

When trying to run this I get an XamlParseException with InnerException of InvalidProgramException. All I did was drag the control on, and add some ListPickerItem. Removing the items still results in the error, removing the ListPicker control completely allows the page to be shown with no error.

I'm sure I've missed something, but any documentation I have read seems to point towards this markup being fine, including http://windowsphonegeek.com/articles/listpicker-for-wp7-in-depth

I can provide any other info required.


回答1:


ListPickerItem is a class used internally by the ListPicker and should not be used directly.

If you just want to add a list of items, you can use strings to do it, like this:

Add a new namespace on top of the Page to access the String class:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

Then, just change the ListPicker code to this:

<toolkit:ListPicker>
    <sys:String>Win</sys:String>
    <sys:String>Place</sys:String>
    <sys:String>Lose</sys:String>
</toolkit:ListPicker>



回答2:


The problem was that the wrong dlls had been registered, i.e. 7 and not 7.1. I had to uninstall and reinstall to get it to update correctly and it worked.



来源:https://stackoverflow.com/questions/10155688/microsoft-phone-controls-toolkit-listpicker-throws-xamlparseexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!