- Mastering Visual Studio 2017
- Kunal Chowdhury
- 77字
- 2021-07-15 17:26:43
Working with inline code in XAML pages
You can write inline programming code (C# or VB.NET) within the XAML page, using the x:Code directive and must be surrounded by <![CDATA[...]]> to escape the contents for XML. This can interact within the same XAML page:
<Window x:Class="MyWpfApplication.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Main Window" Height="350" Width="525"> <Grid> <Button Click="Button_Click" Content="Click Here" /> <x:Code> <![CDATA[ void Button_Click(object sender, RoutedEventArgs e) { // event implementation } ]]> </x:Code> </Grid> </Window>
Try to avoid using the inline code in the XAML page, as it violates the separation between the designer and the code behind. Also, other language-specific programming features are not supported in inline coding.
推薦閱讀
- MySQL 8從入門到精通(視頻教學版)
- Three.js開發指南:基于WebGL和HTML5在網頁上渲染3D圖形和動畫(原書第3版)
- Julia機器學習核心編程:人人可用的高性能科學計算
- Android開發:從0到1 (清華開發者書庫)
- 從Java到Web程序設計教程
- Python深度學習原理、算法與案例
- Laravel Application Development Blueprints
- Nagios Core Administration Cookbook(Second Edition)
- TypeScript圖形渲染實戰:2D架構設計與實現
- Python編程快速上手2
- Java服務端研發知識圖譜
- Microsoft XNA 4.0 Game Development Cookbook
- Getting Started with Backbone Marionette
- C# 7.0核心技術指南(原書第7版)
- 梔子貓的奇幻編程之旅:21天探索信息學奧賽C++編程