posts - 280, comments - 318, trackbacks - 0

My Links

News

View Steve Michelotti's profile on LinkedIn

Twitter












Tag Cloud

Archives

Post Categories

Blend Bloggers

Bloggers that I follow

Books

F# Bloggers

F# Communities

F# Online Books

Fonts

HTML CSS ASP

Machine Learning

My Links

My Local UserGroups

My Online Presence

MY SA Links

Online Seminars

SA Software Companies

Web Design

XAML Oddities – Inline C# code in a XAML file (aka UTCC approach)

 

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.

Print | posted on Tuesday, January 31, 2012 8:08 PM | Filed Under [ C# ]

Feedback

Gravatar

# re: XAML Oddities – Inline C# code in a XAML file (aka UTCC approach)

Yep, just tested that and the button actually does work. Very cool indeed and didn't know one could do that. Thanks for sharing.
2/2/2012 6:44 AM | ct
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: