網站首頁 編程語言 正文
一、簡介
如下面代碼所示,在WPF項目的設計界面可以通過<x:Code> <![CDATA[? //write your code?]]></x:Code>節點,可添加后臺邏輯執行的代碼和方法,實現方法的調用和執行。
二、代碼
WPF設計部分代碼:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication2"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="800" Width="500">
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="-150,-165,0,0" VerticalAlignment="Top" Width="85" Click="button_Click"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="-150,-75,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
<x:Code>
<!--此處可以寫后臺代碼-->
<![CDATA[
private void button_Click(object sender, RoutedEventArgs e)
{
test();
string test_message = "dddddd";
textBox.Text = test_message;
}
]]>
</x:Code>
</Window>
后臺的test方法:
當然,此方法寫在設計界面里也可以,此處為了清晰的看到測試對比效果,前后端方法分開寫。
public void test()
{
string mes = "test message";
MessageBox.Show(mes);
}
二、測試效果
原文鏈接:https://www.cnblogs.com/wml-it/p/14885505.html
相關推薦
- 2022-11-05 一篇文章說清楚?go?get?使用私有庫的方法_Golang
- 2022-07-16 (ES6以上以及TS) Map對象轉數組
- 2022-10-06 Django數據映射(一對一,一對多,多對多)_python
- 2023-01-07 anaconda?navigator打不開問題的解決方法_python
- 2022-12-21 Redis數據庫原理深入刨析_Redis
- 2023-01-14 GoLang內存模型詳細講解_Golang
- 2022-08-19 存儲引擎的應用場景
- 2022-10-27 Apache?Hive?通用調優featch抓取機制?mr本地模式_Linux
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支