Geeks With Blogs
Mark Pearl

 

Something I came across that I never knew was possible was that you can put c# code inline in a XAML file in a WPF app (I assume this would work in Silverlight as well). Not that you would ever want to do this, but sometimes you just need those geek points!

Make a WPF application, in the XAML file put the following…

<Grid>
        <Button x:Name="button1" Click="button1_click">test</Button>
        <x:Code>
            void button1_click(object sender, RoutedEventArgs e)
            {
                button1.Content = "Inline Code Works!!";
            }
        </x:Code>        
</Grid>

 

There you go, plain old code inline in a XAML file, I like to call this UTCC approach, better known as ultimately tightly coupled code.

Posted on Tuesday, January 31, 2012 8:08 PM C# | Back to top


Comments on this post: XAML Oddities – Inline C# code in a XAML file (aka UTCC approach)

# re: XAML Oddities – Inline C# code in a XAML file (aka UTCC approach)
Requesting Gravatar...
Yep, just tested that and the button actually does work. Very cool indeed and didn't know one could do that. Thanks for sharing.
Left by ct on Feb 02, 2012 6:44 AM

Your comment:
 (will show your gravatar)


Copyright © MarkPearl | Powered by: GeeksWithBlogs.net