官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 黄大仙区| 乌拉特中旗| 满城县| 西盟| 通榆县| 荣成市| 确山县| 沾益县| 东城区| 嘉定区| 玛纳斯县| 澄迈县| 柳江县| 广丰县| 巴彦县| 宣化县| 海兴县| 双鸭山市| 前郭尔| 南宫市| 裕民县| 揭东县| 辽宁省| 大方县| 扬州市| 织金县| 壶关县| 建宁县| 手机| 郑州市| 昔阳县| 茌平县| 公安县| 阿克陶县| 珲春市| 乡宁县| 泰顺县| 衡南县| 莎车县| 灯塔市| 农安县|