- 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.
推薦閱讀
- 大話PLC(輕松動漫版)
- 數據庫系統原理及MySQL應用教程(第2版)
- Access 2010數據庫基礎與應用項目式教程(第3版)
- Kotlin編程實戰:創建優雅、富于表現力和高性能的JVM與Android應用程序
- Learning R for Geospatial Analysis
- C專家編程
- 編寫高質量代碼:改善Objective-C程序的61個建議
- MySQL數據庫應用實戰教程(慕課版)
- Flink核心技術:源碼剖析與特性開發
- Java面向對象程序設計教程
- Hands-On Artificial Intelligence with Unreal Engine
- Netty 4核心原理與手寫RPC框架實戰
- Learning Scrapy
- Effective Python:編寫高質量Python代碼的90個有效方法(原書第2版)
- 數據庫技術及應用(Access)(第2版)