2

Possible Duplicate:
Access DisplayName in xaml

Is there a standard way in XAML to bind to an attribute of an object? I know this is a similar question to this one and that I can create a MarkupExtension or use a Converter. I'm just wondering if there's some built in markup or native support in .net 4.5.

i.e.

// Some class with an Attribute:

[Description("A description")]
class Foo
{
}

// XAML - DataContext is a Foo object
<UserControl DataContext="{StaticResource myFoo}"  
  <TextBlock Text="{Binding ?Description?}"/>
</UserControl>
Community
  • 1
  • 1
hashlock
  • 590
  • 1
  • 6
  • 15
  • Yeah that's why I reference that post. I just thought since it was a year old there might be a change in .net 4.5 or something. – hashlock Dec 19 '12 at 18:55

2 Answers2

2

There is no native support for binding to an attributes. You should write your own markup extension.

Dzmitry Martavoi
  • 6,867
  • 6
  • 38
  • 59
2

No; it needs to be a an explicit Property or implicitly inherited via the DataContext, ie...{Binding}.

Aaron McIver
  • 24,527
  • 5
  • 59
  • 88