检查组合框中选定的值 - SilverLight4
已解决
当从组合框中选择特定位置时,我试图执行一些操作,但无法使其工作,谷歌给我的答案不起作用,尽管人们说它起作用。
所以我在 XAML 中得到了这个:
<ComboBox Height="27" HorizontalAlignment="Left" Margin="178,96,0,0" Name="comboBox1" VerticalAlignment="Top" Width="142" SelectionChanged="comboBox1_SelectionChanged" SelectedValuePath="Content">
<ComboBoxItem IsSelected="True">Szafa</ComboBoxItem>
<ComboBoxItem>Segment</ComboBoxItem>
<ComboBoxItem>Łóżko</ComboBoxItem>
<ComboBoxItem>Stół</ComboBoxItem>
</ComboBox>
在 XAML.cs 中
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((comboBox1.SelectedItem as ComboBoxItem).Content.ToString() == "Szafa")
MessageBox.Show("TEST");
}
也尝试了这个:
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string UserSelect = comboBox1.SelectedValue.ToString();
if (UserSelect == "Szafa")
MessageBox.Show("TEST");
}
SilverLight 插件停止在 100% 并且不显示任何内容。在我删除 if 条件后,它起作用了......出了什么问题?
解决了
我通过以下方式解决了这个问题:
if ((sender as ComboBox).SelectedValue.ToString() == "Szafa")
{
MessageBox.Show("TEST");
}
对于任何未来来到这里的人......
SOLVED
I'm trying to make some actions when specific position is selected from combobox, but can't get it to work, Google gave me answer that doesn't work, though people say it does.
So I've got this in XAML:
<ComboBox Height="27" HorizontalAlignment="Left" Margin="178,96,0,0" Name="comboBox1" VerticalAlignment="Top" Width="142" SelectionChanged="comboBox1_SelectionChanged" SelectedValuePath="Content">
<ComboBoxItem IsSelected="True">Szafa</ComboBoxItem>
<ComboBoxItem>Segment</ComboBoxItem>
<ComboBoxItem>Łóżko</ComboBoxItem>
<ComboBoxItem>Stół</ComboBoxItem>
</ComboBox>
And this in XAML.cs
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((comboBox1.SelectedItem as ComboBoxItem).Content.ToString() == "Szafa")
MessageBox.Show("TEST");
}
Also tried this:
private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string UserSelect = comboBox1.SelectedValue.ToString();
if (UserSelect == "Szafa")
MessageBox.Show("TEST");
}
SilverLight plugin stops on 100% and doesn't show any content. After I remove if condition, it works... What's wrong?
SOLVED
I solved this via:
if ((sender as ComboBox).SelectedValue.ToString() == "Szafa")
{
MessageBox.Show("TEST");
}
For any future people who come here...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
前 8 小时我无法回答这个问题,所以现在就回答。我通过以下方式解决了这个问题:
对于任何未来来到这里的人......
I couldn't answer this for first 8h, so doing it now. I solved this via:
For any future people who come here...