首页 新闻 会员 周边

wpf中给按钮绑定一个bool属性

0
悬赏园豆:30 [已解决问题] 解决于 2013-07-25 09:38

a.xaml

  <Grid x:Name="root">
        <TextBox Text="{Binding str1}"  Width="200" Height="25" Margin="92,23.5,92,0" VerticalAlignment="Top" d:LayoutOverrides="Height"/>
        <Button IsEnabled="{Binding YN}" Margin="92,106,92,116" Content="按钮"/>
        <TextBox Text="{Binding str2}" Width="200" Height="25" Margin="92,0,92,28.5" VerticalAlignment="Bottom" d:LayoutOverrides="Height"/>
        
    </Grid>

 

a.xaml.cs

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        void MainWindow_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            //apps.Resize(root.ActualWidth, root.ActualHeight);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //apps.Resize(root.ActualWidth, root.ActualWidth);
            root.DataContext = new BingO() { str1 = "qq", str2 = "ww2" };
        }
    }

    public class BingO
    {
        public string str1 { get; set; }

        public string str2 { get; set; }

        public bool YN
        {
            get
            {
                return str1.Length > str2.Length;
            }
        
        }
    }

 

如何定义 BingO 的属性 才能让正常 工作? 根据str1, str2 的实时输入而改变 按钮是否可用?

问题补充:

请大侠们 帮我 写出 类定义,

啊啦星的主页 啊啦星 | 初学一级 | 园豆:95
提问于:2012-06-25 16:15
< >
分享
最佳答案
2

实现INotifyPropertyChenged接口

收获园豆:30
粒粒淘 | 菜鸟二级 |园豆:232 | 2012-11-09 15:32
其他回答(3)
0
BingO的属性申明没有属性值的改变通知事件
八戒的师傅 | 园豆:1472 (小虾三级) | 2012-06-26 00:30
1

你的 BingO类 实现INotifyPropertyChenged接口。当str1和str2值变化的时候 通知YN

Lee's Blog | 园豆:530 (小虾三级) | 2012-07-01 22:13
0

只接在str1和str2两个TextBox 的PropertyChenged事件里设置按钮是否可用。比 BingO类继承INotifyPropertyChenged接口容易多啦!

lanyefeng2008 | 园豆:20 (初学一级) | 2012-09-07 22:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册