Check this:
<Window x:Class="WpfApplication1.TestBrowser"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Initialize Component Test"
Height="300"
Width="300">
<StackPanel>
<ListBox x:Name="lb"/>
<x:Code>
<![CDATA[
public TestBrowser()
{
InitializeComponent();
lb.ItemsSource = new[] { "Hey" };
}
]]>
</x:Code>
</StackPanel>
</Window>
When such a XAML file is compiled, the content inside the x: Code element becomes plopped inside the partial class in the .g.cs file.
I still do not recommend this practice. For me, this makes the code less readable, and I'm not sure if Blend or Kaxaml understands it.
source
share