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

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.

主站蜘蛛池模板: 苍南县| 石河子市| 广平县| 景洪市| 尉犁县| 连云港市| 思南县| 巴林右旗| 庆阳市| 新化县| 凌云县| 喀什市| 高平市| 阿巴嘎旗| 定兴县| 贡嘎县| 洮南市| 昭平县| 万山特区| 东兴市| 桦甸市| 巴林右旗| 新沂市| 如东县| 禄丰县| 保德县| 咸阳市| 深圳市| 米泉市| 衡水市| 华容县| 平山县| 新源县| 社会| 海安县| 缙云县| 横山县| 贺州市| 鲁山县| 黑河市| 绵竹市|