我试图获得一个按钮(点击时)以显示隐藏的单选按钮rbChoice2.Visibility = Visibility.Visible
。单选按钮位于另一个窗口上,需要另一个按钮save_Click来显示窗口并向单选按钮内容发送一个值。所以我需要第一个按钮,在单击save_Click之前已经使单选按钮可见。
我对WPF很新,虽然我已经尝试将可见性代码和内容代码放在第一个按钮中,但它不起作用。这是我尝试过的代码。
public partial class Create : Window
{
public Create()
{
InitializeComponent();
}
private void addChoice1_Click(object sender, RoutedEventArgs e)
{
choice2.Visibility = Visibility.Visible;
addChoice2.Visibility = Visibility.Visible;
addChoice1.Visibility = Visibility.Hidden;
Save obj = new Save();
obj.rbChoice2.Visibility = Visibility.Visible;
obj.rbChoice2.Content = choice2.Text;
}
private void save_Click(object sender, RoutedEventArgs e)
{
Save objS = new Save();
objS.lbTest.Content = question.Text;
objS.rbChoice1.Content = choice1.Text;
objS.rbChoice2.Content = choice2.Text;
objS.ShowDialog();
}
}
我在编码时学习xaml,所以我希望我能正确地提出这个问题。真的希望有人可以帮忙解决这个问题。非常感谢
答案 0 :(得分:0)
你有2个窗口副本 - " obj"和" objS"根本没有关系。
试试这个:
public partial class Create : Window
{
public Create()
{
InitializeComponent();
}
Save obj = new Save();
private void addChoice1_Click(object sender, RoutedEventArgs e)
{
choice2.Visibility = Visibility.Visible;
addChoice2.Visibility = Visibility.Visible;
addChoice1.Visibility = Visibility.Hidden;
obj.rbChoice2.Visibility = Visibility.Visible;
obj.rbChoice2.Content = choice2.Text;
}
private void save_Click(object sender, RoutedEventArgs e)
{
obj.lbTest.Content = question.Text;
obj.rbChoice1.Content = choice1.Text;
obj.rbChoice2.Content = choice2.Text;
obj.ShowDialog();
}
}