【发布时间】:2015-08-24 06:42:06
【问题描述】:
我的 wpf 中有一个组合框和两个名为:
- 发送
- 接收。
我想让组合框在首次加载 WPF 时显示一般消息(发送/接收)。 我尝试将字符串应用于 XAML 中的 Text 属性,但没有成功:
<ComboBox x:Name="opBox" HorizontalAlignment="Left" Text="Send/Receive"/>
有什么方法可以应用此文本使其不作为一个项目?
In addition, when one of the items is selected I'm hiding or making visible the appropriate button by an event called SelectionChanged.但是,如果用户再次选择一般消息发送/接收,我希望 2 个按钮隐藏在一起。当我尝试在 SelectionChanged 中执行此操作时,出现了一些错误。
更新: 这是我的 SelectionChanged 事件:
private void opBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (opBox.SelectedIndex == 1)//Send
{
mySendButton.Visibility = Visibility.Visible;
myReceiveButton.Visibility = Visibility.Hidden;
}
else if(opBox.SelectedIndex==2)//Receive
{
mySendButton.Visibility = Visibility.Hidden;
myReceiveButton.Visibility = Visibility.Visible;
ClearTextBox();
}
else if (opBox.SelectedIndex == 0)//Send or Receive
{
mySendButton.Visibility = Visibility.Hidden;
myReceiveButton.Visibility = Visibility.Hidden;
}
【问题讨论】:
标签: c# combobox wpf-controls