導航:首頁 > 程序命令 > 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命令相關的資料

熱點內容
apriori演算法的java 瀏覽:691
jscanvas壓縮圖片 瀏覽:370
單片機與汽車單片機有何不同 瀏覽:949
獸醫雲平台伺服器 瀏覽:304
php循環字母 瀏覽:646
盛達是什麼APP 瀏覽:206
android計算屏幕高度 瀏覽:660
自己做紅包解壓球 瀏覽:482
pdf很貴嗎 瀏覽:502
如何搶購騰訊雲伺服器 瀏覽:396
電子書app源碼 瀏覽:877
程序員在上班的時候 瀏覽:406
游戲壓縮文件夾怎麼刪除 瀏覽:427
百度新聞app是什麼 瀏覽:896
自動化對初級編程的影響 瀏覽:114
單片機綜合課程設計 瀏覽:609
程序員小嚴 瀏覽:814
如何下載歡樂走app 瀏覽:447
程序員節公司請美女 瀏覽:18
三本程序員好嗎 瀏覽:24