[UWP]读取两个组合框中的组合框值 [英] [UWP]reading combobox value in two comboboxes

查看:80
本文介绍了[UWP]读取两个组合框中的组合框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MainPage.xaml上有一个带有两个组合框的通用Windows应用程序。我需要能够读取组合框的当前内容以指导程序流程。以下是组合框;

I have a Universal Windows app with two comboboxes on MainPage.xaml. I need to be able to read the current content of the comboboxes to direct program flow. Here are the comboboxes;

andi我在测试按钮中有以下代码,

andi I have the following code in a button for testing,

字符串m_cbvalue工作正常,但m_cbvalue2给出错误;

String m_cbvalue works fine, but m_cbvalue2 give the error;

System.InvalidCastException:无法转换对象键入'System.String'以键入'Windows.UI.Xaml.Controls.ComboBoxItem

System.InvalidCastException: Unable to cast object of type 'System.String' to type 'Windows.UI.Xaml.Controls.ComboBoxItem

发生了什么!有相同的!

What going on! There the same!

推荐答案

我希望用户使用第一个组合框RadioCategory进行选择。根据该选择,我更改用户随后选择的第二个组合框,RadioShows的项目。当第一个组合框更改时,我使用以下代码;

I want the user to use the first combobox RadioCategory to make a selection. Based on that selection I change the Items of the second combobox, RadioShows which the user then selects. I use the following code when the first combobox is changed ;

                      RadioShows.Items.Clear();

                      RadioShows.Items.Add(" Item1");

                      RadioShows.Items.Add(" Item2");

                     RadioShows.Items.Clear();
                     RadioShows.Items.Add("Item1");
                     RadioShows.Items.Add("Item2");

不知何故,一旦这三行代码运行,我检查了值RadioShows组合框它给我错误;

Somehow once those three lines of code are run and I check the value of the RadioShows combobox it gives me the error;

System.InvalidCastException:无法将'System.String'类型的对象强制转换为'Windows.UI.Xaml.Controls.ComboBoxItem

当我检查RadioShows组合框的值时。它会以某种方式改变对象。 当我检查值时,如何更改RadioShows组合的项目而不会出现错误?

when I check the value of RadioShows combobox. It apears it changes the object somehow.  How would I change the items of the RadioShows combo and not get the error when I check the value?


这篇关于[UWP]读取两个组合框中的组合框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆