首页 新闻 赞助 找找看

win8 应用商店开发中,button如何通过command绑定事件在后台处理,并判断xaml中输入的内容

0
[已解决问题] 解决于 2013-08-05 14:53
  • 我在xamL中定义了一个button:

     <Button x:Name="btnOK" Style="{StaticResource OKCancelButtonStyle}" Grid.Column="1" HorizontalAlignment="Left">
                                <Button.Content>
                                    <Grid>
                                        <Image Source="/Assets/Images/Icons/button_ok.png" Stretch="None"/>
                                        <TextBlock Text="OK" Style="{StaticResource Size32TextBlock}"/>
                                    </Grid>
                                </Button.Content>
                                <inter:Interaction.Triggers>
                                    <inter:EventTrigger EventName="Click">
                                        <inter:InvokeCommandAction Command="{Binding BtnOKCommand}" CommandParameter="{Binding ElementName=btnOK}"/>//这里如何把本页面的用户在nameTextBox中输入的名字,和passwordTextBox中的密码一起传到后台的BtnOKCommand方法中进行判断名字和密码是否正确?正确再转入我想进人多页面...
                                    </inter:EventTrigger>
                                </inter:Interaction.Triggers>
                            </Button>

    下面是后台BtnOKCommand的定义

    private RelayCommand<RoutedEventArgs> btnOKCommand;
            public RelayCommand<RoutedEventArgs> BtnOKCommand
            {
                get
                {
                    return btnOKCommand ?? (btnOKCommand = new RelayCommand<RoutedEventArgs>((args) => BtnOK(args)));
                }
            }

            object BtnOK(RoutedEventArgs args)
            {//是在这里写还是在哪里怎么写,对那个页面的内容进行判断?
                Helpers.NavigateHelper.Navigate(typeof(Views.Main.MainPage));

                return null;
            }

    先谢谢了

zihaobiao的主页 zihaobiao | 初学一级 | 园豆:200
提问于:2013-03-21 13:42
< >
分享
最佳答案
0

 

你的问题我写了一篇文章   你看看   希望可以帮你解决问题!   http://www.cnblogs.com/BeiJing-Net-DaiDai/p/3227611.html

 

xaml文件 :

 Command="{Binding btn_Click}"

只用Command 就好

xaml页面后台:

viewmodel对象.txtName=txtName; 

viewmodel对象.txtPassword=txtPassword;......

this.DataContext=viewmodel对象

 

viewmodel  里面定义全局变量和要传递的控件类型相同public TextBox txtName{get;set;}public TextBox txtPassword{get;set;}

事件处理:

public ICommand btn_Click

get{

  return new RelayCommand(()=>{

    //处理代码

 

  });

}

}

 

奖励园豆:5
未雨先惆 | 菜鸟二级 |园豆:209 | 2013-07-31 13:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册