- 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.
推薦閱讀
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- Puppet 4 Essentials(Second Edition)
- 樂學Web編程:網站制作不神秘
- Oracle 12c中文版數據庫管理、應用與開發實踐教程 (清華電腦學堂)
- Android 7編程入門經典:使用Android Studio 2(第4版)
- C語言從入門到精通(第4版)
- 用Flutter極速構建原生應用
- 零基礎學Python網絡爬蟲案例實戰全流程詳解(高級進階篇)
- bbPress Complete
- SQL Server 2016數據庫應用與開發
- Windows Phone 7.5:Building Location-aware Applications
- Create React App 2 Quick Start Guide
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- Node.js 12實戰
- Kubernetes進階實戰