- 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.
推薦閱讀
- vSphere High Performance Cookbook
- C/C++算法從菜鳥到達人
- Visual C++實例精通
- 算法大爆炸:面試通關步步為營
- Windows Server 2012 Unified Remote Access Planning and Deployment
- Getting Started with SQL Server 2012 Cube Development
- 表哥的Access入門:以Excel視角快速學習數據庫開發(第2版)
- Java面向對象程序設計
- Java網絡編程實戰
- Internet of Things with ESP8266
- Unity 5.X從入門到精通
- Kotlin進階實戰
- 青少年Python趣味編程
- Java服務端研發知識圖譜
- 城市信息模型平臺頂層設計與實踐