当前位置:网站首页>19. Implementation of MVVM architecture based on WPF event to command
19. Implementation of MVVM architecture based on WPF event to command
2022-06-25 12:09:00 【komla168】
Preface :MVVM Use in development mode Command It's very convenient , But many controls do not Command, such as Text Focus of attention 、 Loss of focus, etc , Are directly related to... Through events View Background program interaction . At this time, if you still want to ViewModel Realization Command function , You need something else .
Be clear ,Microsoft.Expression.Interactions and System.Windows.Interactivity Assembly at Blend Only in tools , however , I don't know when to start , These two assemblies are deprecated , Now change to Microsoft.Xaml.Behaviors 了 .
One 、System.Windows.Interactivity

You can see it , Rely on the Framwork The minimum version is 4.0, Is the highest 4.8, And only support .NETFramwork edition .
1.1 brief introduction
If the target framework is .NETFramwork The various versions of , such as 4,4.8 Equal Edition , Need to introduce System.Windows.Interactivity.dll Dynamic library , It can also be done through NuGet Download , It's just , This library , Now the update has stopped , But it can still be used after downloading . The officially recommended alternative library is another library Microsoft.Xaml.Behaviors.

If the target framework is .NET Core And above , It can also be used. , Only there will be a prompt to use .NETFramwork Restore this library in other versions of .

1.2 Use
xaml Reference namespace in , There are two ways , Some versions may not work , The author here aims to frame .NETFramwork4.8 and .NET5 To test , It's all right .
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"<TextBox Text="fengxiong" VerticalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding OpenSerialPortCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="GotFocus">
<i:InvokeCommandAction Command="{Binding OpenSerialPortCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
here Interaction There are two choices , One is Triggers, The other is Behaviors, The author searched the relevant literature on the Internet , I found that some people said they used Behaviors, In fact, it is still used Triggers.
Two 、Microsoft.Xaml.Behaviors
2.1 brief introduction
The information found on the Internet by the author shows that , The first version is from 2018 year 12 month 3 Started on .

and System.Windows.Interactivity.WPF Stop yes 2013 year 3 month 10 Number , And there is only one version .

On the official website System.Windows.Interactivity The creation display time is 2017 year 10 month 11

Microsoft.Xaml.Behaviors The relevant information is as follows .


2.2 Use
and System.Windows.Interactivity The way to use it is the same , Just changed the namespace . Download first and then reference .

xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
<TextBox Text="fengxiong" VerticalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction Command="{Binding OpenSerialPortCommand}"/>
</i:EventTrigger>
<i:EventTrigger EventName="GotFocus">
<i:InvokeCommandAction Command="{Binding OpenSerialPortCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>3、 ... and 、 Citations
3.2 System.Windows.Interactivity Namespace | Microsoft Docs
3.4 WPF in System.Windows.Interactivity Use _lpb914 The blog of -CSDN Blog
3.5 NuGet Gallery | Microsoft.Xaml.Behaviors.Wpf 1.1.39
3.6 NuGet Gallery | System.Windows.Interactivity.WPF 2.0.20525
边栏推荐
- VFP calls the command line image processing program, and adding watermark is also available
- ThingsPanel 發布物聯網手機客戶端(多圖)
- R语言dplyr包filter函数过滤dataframe数据中指定数据列的内容不是(不等于指定向量中的其中一个)指定列表中的数据行
- Solution to the timeout scenario of Flink streaming computing (official live broadcast)
- 2022年首期Techo Day腾讯技术开放日将于6月28日线上举办
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用summary函数获取模型汇总统计信息
- Develop two modes of BS mode verification code with VFP to make your website more secure
- 20、wpf之MVVM命令绑定
- Le détour d'un ingénieur en matériel
- Manually rollback abnormal data
猜你喜欢

devsecops与devops的理解与建设

Customize to prevent repeated submission of annotations (using redis)

Explanation of ideas and sharing of pre-processing procedures for 2021 US game D (with pre-processing data code)

ROS notes (06) - definition and use of topic messages

揭秘GaussDB(for Redis):全面对比Codis

VFP develops a official account to receive coupons, and users will jump to various target pages after registration, and a set of standard processes will be sent to you

What should I do to dynamically add a column and button to the gird of VFP?

Idea local launch Flink task

SQL server saves binary fields to disk file

15、wpf之button样式小记
随机推荐
机器学习自学成才的十条戒律
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用epiDisplay包的lrtest函数执行多个模型似然比检验对比两个模型的性能是否有差异
Kotlin学习笔记
Pd1.4 to hdmi2.0 adapter cable disassembly.
Redis雪崩、穿透和击穿是什么?
如果你也想做自媒体,不妨听大周给您点建议
SQL function summary
Specific meanings of node and edge in Flink graph
Evaluating the overall situation of each class in a university based on entropy weight method (formula explanation + simple tool introduction)
Continue to cut the picture after the ArcGIS Server is disconnected
What are redis avalanche, penetration and breakdown?
图片打标签之获取图片在ImageView中的坐标
Flink deeply understands the graph generation process (source code interpretation)
黑马畅购商城---8.微服务网关Gateway和Jwt令牌
ROS notes (06) - definition and use of topic messages
Which securities company's account is better and safer to open
Flink batch key points (personal translation)
SDN系统方法 | 9. 接入网
. Using factory mode in net core
Black Horse Chang Shopping Mall - - - 3. Gestion des produits de base