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

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.

主站蜘蛛池模板: 揭西县| 德兴市| 临武县| 滨州市| 大宁县| 昌都县| 禄劝| 十堰市| 中阳县| 大埔县| 奇台县| 株洲县| 栾城县| 奉新县| 天全县| 基隆市| 奈曼旗| 方城县| 汕头市| 泸定县| 永德县| 福鼎市| 闵行区| 恭城| 巨鹿县| 秦皇岛市| 萍乡市| 五河县| 吴江市| 望都县| 丘北县| 华安县| 通化县| 迁安市| 汨罗市| 东海县| 满城县| 陆河县| 徐汇区| 山阳县| 龙海市|