导航:首页 > 程序命令 > wpf命令

wpf命令

发布时间:2022-02-14 08:15:31

1. wpf command 是如何使用的求简单直接的代码

写一个类用来申明密令:
public static class StuCommand
{
public static readonly RoutedCommand BtnStu=new RoutedCommand("查看学生信息",typeof(StuCommand));
}

到需要用到命令xaml的cs界面注册(好比 student.xaml.cs):
其本身会有一个构造函数 public student(){};
在自己写一个静态的在里面注册密令;
static student()
{
CommandManager.RegisterClassCommandBinding(typeof(student),
new CommandBinding(StuCommand.BtnStu,BtnStuEvevtsExecute, BtnStuEvevtsCanExecute));
}

static void BtnStuEvevtsExecute(object sender,ExecutedToutedEventArgs e)
{
//这里很灵活,可以拿按钮的数据上下文等等,下面只是最简单的
var BtnStuManager=sender as student;
if(BtnStuManager!=null)
{
//此处写当点击按钮要执行的代码,建议封装一个方法在这里调用。比如下面声明的Refresh()方法

BtnStuManager.Refresh();
}
}

static void BtnStuEvevtsCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
var BtnStuManager=sender as student;

e.CanExecute= true/false/一些条件 //为真按钮启用,为假按钮置灰不能用
}

public void Refresh()
{
//这是方法,代码就不写了。
}

然后在student.xaml页面中绑定:
<Button .........
Command="{x:Static local:StuCommand.BtnStu}"
CommandTarget="{Binding RelativeSource={RelativeSource AncestorType=local:student}}"

2. wpf 命令系统 Button 不可用

如下设置:
<StackPanel FocusManager.IsFocusScope="True"> (这里:关键点->焦点范围)
<TextBox x:Name="textBoxA"/>
<Button x:Name="buttonA" Command="Copy" Content="{Binding Path=Command.Text,RelativeSource={RelativeSource Self}}"/>
</StackPanel>

3. wpf的命令怎么绑定多个条件

一般来说,条件不符合时,要禁用按钮。而不是等到执行时,再去判断条件。
WPF的ICommand模式,或者RoutedCommand模式都支持CanExecute回调。
你可以在CanExecute中判断条件。
比如下例,CanExecute判断名字输入框是否空白,并相应禁用按钮。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local ="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Window.CommandBindings>
<CommandBinding Command="{x:Static local:MainWindow.MyCommand}"
CanExecute="CanExecuteMyCommand"
Executed="ExecutetMyCommand" />
</Window.CommandBindings>
<StackPanel>
<Label>名字:</Label>
<TextBox Name="textbox1"/>
<Button Command="{x:Static local:MainWindow.MyCommand}" Content="提交" Margin="0 10" />
</StackPanel>
</Window>
using System;
using System.Windows;
using System.Windows.Input;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void CanExecuteMyCommand(object sender,CanExecuteRoutedEventArgs e)
{
e.CanExecute = !string.IsNullOrEmpty(this.textbox1.Text);
}
private void ExecutetMyCommand(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("Hello " + this.textbox1.Text);
}
public static RoutedCommand MyCommand = new RoutedCommand();
}
}

4. wpf程序调用cmd命令行的方法(C#语言调用C++写的程序)

string path = "你的exe文件的路径";
if (File.Exists(path))
{

Process.Start(path);
}

5. WPF命令和事件之间的区别是什么

一般来说,你可以做几乎与事件与命令,它是处理用户交互只是一个不同的模式。

命令在WPF让您的命令处理程序的实现移动到楼内设有商务层。命令结合启用状态executation,所以一切都在发生。里德更多通过搜索MVVM模式。

命令更复杂的实施在第一,所以如果你的应用程序是小,你应该考虑的只是坚持到事件。

6. wpf command如何传参数

比如定义了这样一个命令:
public ICommand SaveCommand
{
get { return new RelayCommand(p=>this.Save(),p=>this.CanSave);}
}
在这个命令里面,要执行的操作就是Save()这个方法中代码,命令的参数就是CanSave这个属性的值。希望对你有帮助,还有疑问请追问或是Hi

7. WPF中自定义控件怎么在命令中阻止路由冒泡

在后台使用 事件 或者在grid的事件中判断sender 设置e.Handled 为false

8. c#wpf ribbon菜单命令怎么写

//System.Color是一个系统自定义的枚举,可以选择颜色。 如果是在WPF编程中,则应该使用TextBox.Background属性,结果量个Brush,以实现过度色背景等各种不同效果的背景。

9. 如何将WPF中的命令绑定到控件的双击事件处理程序

在视图编辑的界面,右键控件属性,看到那个黄色的闪电图标没,点击,里面就是这个控件可以相应的事件,然后你双击相应的事件,程序会为你自动生成函数头部的

10. wpf mvvm命令绑定怎么传参数

mvvm种架构模式虽依赖其东西iOSReactiveCocoa实现起便点RAC(self. userNameLabel, text) = RACObserve(self. viewModel, userName);
比labelviewModeluserName绑定ViewModeluserName改变userNameLabel自更新用手setText
,

阅读全文

与wpf命令相关的资料

热点内容
单片机发at命令 浏览:390
java方法参数类 浏览:61
直螺纹套筒连接加密 浏览:150
擒牛决指标源码 浏览:903
python中有哪六种标准数据类型 浏览:43
云服务器日志是什么意思 浏览:70
怎么转安卓到ios的王者荣耀 浏览:433
vapp怎么下 浏览:667
linuxbt命令 浏览:284
安卓怎么注销苹果区和平营地 浏览:142
怎么去调整电脑文件夹的桌面 浏览:210
解压汽车绿本可以找代理人吗 浏览:64
我的世界命令方块在哪 浏览:315
linuxzone 浏览:746
androidapi版本号 浏览:784
小猪佩奇配音解压吃东西 浏览:285
程序员怎么申请公司年会 浏览:870
圈店app的预约头条功能怎么样 浏览:34
云服务器设置ad域 浏览:316
我的世界无尽贪婪奇点压缩器 浏览:394