当前位置: 首页 > news >正文

泉州做网站开发公司/私人网站服务器

泉州做网站开发公司,私人网站服务器,视频网站做板块栏目,网店营销推广方案论文在 XAML 中 1,创建一个command对象,可以直接使用RoutedCommand,然后通过CommandBinding来指定Execute和CanExecute; 2,指定 Command 。例子中使用的是CheckBox, 实际上Command是ButtonBase的成员,所以,所有…

在 XAML 中

1,创建一个command对象,可以直接使用RoutedCommand,然后通过CommandBinding来指定Execute和CanExecute;

2,指定 Command 。例子中使用的是CheckBox, 实际上Command是ButtonBase的成员,所以,所有ButtonBase的派生类都适用该方法,如RadioButton, RepeatButton,等等。

Command 是一个 StaticResource
<Window
x:Class="Program.Window1"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
Title
="Window1" Height="300" Width="300">
<Window.Resources>
<RoutedCommand x:Key="MyCmd"/>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="{StaticResource MyCmd}" CanExecute="MyCmd_CanExecute" Executed="MyCmd_Executed"/>
</Window.CommandBindings>
<Grid>
<CheckBox Command="{StaticResource MyCmd}"
CommandParameter
="{Binding IsChecked, RelativeSource={RelativeSource Self}}"
Content
="I have been binded to a command"/>
</Grid>
</Window>

 

使用 M-V-VM 模式

可以在你的Model或者View Model中提供一个ICommand的Property被Binding. 注意,上面的方法中是StaticResource,这里是Binding

 

Model 代码
namespace Program
{
public class Model : INotifyPropertyChanged
{
#region implement interface INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(
this, new PropertyChangedEventArgs(info));
}
}
#endregion

private RelayCommand _myCmd = null;
public ICommand MyCmd
{
get
{
if(_myCmd==null)
_myCmd
= new RelayCommand(param => MyCmdExecute(param));
return _myCmd;
}
}

private void MyCmdExecute(object param)
{
MessageBox.Show(param.ToString());
}
}
}

 

XAML中Command Binding
<Window
x:Class="Program.Window1"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
Title
="Window1" Height="300" Width="300"
>
<Grid>
<Button Command="{Binding MyCmd}" CommandParameter="hello!" Content="I have been bound to a command" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Window>

 

ICommand实现辅助类
namespace Program
{
public class RelayCommand : ICommand
{
#region ICommand realization

[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}

public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested
+= value; }
remove { CommandManager.RequerySuggested
-= value; }
}

public void Execute(object parameter)
{
_execute(parameter);
}

#endregion

readonly Action<object> _execute;
readonly Predicate<object> _canExecute;

public RelayCommand(Action<object> execute)
:
this(execute, null)
{ }

public RelayCommand(Action<object> execute, Predicate<object> canExecute)
{
if (execute == null)
throw new ArgumentNullException("RelayCommand argument can not be null!");

_execute
= execute;
_canExecute
= canExecute;
}
}
}

 

Code Behind里设置DataContext
namespace Program
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
private Model Dat = new Model();

public Window1()
{
this.DataContext = Dat;
InitializeComponent();
}
}
}

 

转载于:https://www.cnblogs.com/yapzhang/archive/2010/08/27/1810226.html

http://www.jmfq.cn/news/4828807.html

相关文章:

  • 商城式网站具备哪些功能吗/重庆网站快速排名提升
  • 国内永久免费crm系统网站推荐/百度账号购买网站
  • 建网站内容/如何快速网络推广
  • wordpress建站教程贴吧/网络销售培训学校
  • 免费搭建商城网站/网络广告营销典型案例
  • 新疆建设兵团农一师检察院网站/陕西seo主管
  • 手机百度 网站提交/搜索引擎seo关键词优化
  • 购物网站建设与实现/b站推广入口2023
  • c2c网站的类型/sem是什么岗位
  • 做本地网站需要什么资质/本周时事新闻概要10条
  • 上海平台网站建设报/域名交易域名出售
  • 手机网站栏目结构图/太极seo
  • wordpress手机网站怎么做/河南seo推广
  • 南城区做网站/精准引流推广
  • wordpress 有图片的文章/百度推广优化师
  • 洛杉矶网站建设/网络营销案例分析报告
  • 网站做cpa/市场营销考试题目及答案2022
  • 浏览网站 需要我安装wordpress/北京百度推广代理公司
  • 建设网站必备条件/销售网站有哪些
  • 网站说建设中/厦门网站推广公司哪家好
  • 资阳房产网站建设/网站建设公司哪家好?该如何选择
  • 宜昌网站制作/seo店铺描述
  • 邯郸做网站流程/360优化大师旧版
  • 乐从网站制作/sem分析
  • 公网ip做网站/深圳搜索排名优化
  • 四川省建设厅官方网站联系电话/爱站seo工具包官网
  • wordpress额外css/品牌推广百度seo
  • 网站备案注销申请书/美容美发培训职业学校
  • 可以做网站的编程有什么/北京百度推广官网首页
  • 网站备案未注销 影响/可视化网页制作工具