简体   繁体   English

WPF,C#使用VS2010

[英]WPF,C# using VS2010

I made Binding with CheckBox ,Lable, implemented BoolToVisibleOrHidden class, means when checkBox1.IsChecked Lable should be displayed, what I want to implement is in checkbox checked EventHandler, I want to implement with MessageBox. 我用CheckBox,Lable做了Binding,实现了BoolToVisibleOrHidden类,意味着当checkBox1.IsChecked Lable应该显示时,我想要实现的是复选框检查的EventHandler,我想用MessageBox实现。 If Messabox.Yes then only Label should be displayed, 如果Messabox.Yes那么只显示Label,

 <CheckBox Name="_checkBoxExpertMode" IsChecked="{Binding Path=DisplayChecked, Mode=TwoWay}" 
 <Lable  Name="_lableDisplay" Visibility="{Binding Path=DisplayChecked, Mode=OneWay, NotifyOnTargetUpdated=True, Converter={StaticResource BoolToVisConverter}}"
                                                          />

 System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Sure", "Some Title", System.Windows.Forms.MessageBoxButtons.YesNo);
              if (dialogResult == System.Windows.Forms.DialogResult.Yes)
            {
                _checkBoxExpertMode.IsChecked = true;
            }
           else if (dialogResult == System.Windows.Forms.DialogResult.No)
           {
               _checkBoxExpertMode.IsChecked = false;
           }

But Label is displaying before Messagebox popup. 但是Label在Messagebox弹出窗口之前显示。

Help me, thanks in advance 请帮助我,提前谢谢

Drop the binding on the checkbox and use the Checkbox.Checked event . 删除复选框上的绑定并使用Checkbox.Checked事件

<CheckBox Name="..." Checked="CheckBox_Checked"  />

In the event handler, display the message box and use a property to indicate if the label should be displayed : 在事件处理程序中,显示消息框并使用属性指示是否应显示标签:

public class MyWindow
{
    public bool ShouldLabelBeDisplayed { get; set; }

    public void CheckBox_Checked(object sender, RoutedEventArgs e)
    {
        DialogResult dialogResult = MessageBox.Show(...);
        if (dialogResult == DialogResult.Yes)
        {
            ShouldLabelBeDisplayed = true;
        }
        else
        {
            ShouldLabelBeDisplayed = false;
        }
    }

Finally, bind the Visible property of your label to this property : 最后,将标签的Visible属性绑定到此属性:

    <Label Name="..." Visibility="{Binding Path=ShouldLabelBeDisplayed, Converter={StaticResource BoolToVisConverter}}" />

It might not be exactly this but you get the idea. 它可能不是这个,但你明白了。

tru to make a property of label to: 将标签属性设为:

yourlabel.Visibility="Hidden". 

Then when you want to show, you should make property: 然后,当你想要展示时,你应该建立财产:

yourlabel.Visibility="Visible".

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM