25

I have a control I 'created' in XAML that I want to access through the Code Behind.

<wincontrols:LiveTileFrameElement Name="PendingAuthsFrame1" Text="Pending" />

this.PendingAuthsFrame1.Text = "334";

However, I get a Build Error on the second statement above stating MyApp.MainWindow does not contain a definition for 'PendingAuthsFrame1' and no extension method.... it keeps going but you get the idea I'm guessing.

What am I missing or doing wrong?

Noam M
  • 3,156
  • 5
  • 26
  • 41
Refracted Paladin
  • 12,096
  • 33
  • 123
  • 233
  • Do you have Telerik.WinControls.UI in project references? LiveTileFrameElement is teleric control for winforms, i am right? – Frank59 Nov 26 '12 at 17:20
  • Yup, I do. Thanks. You just made me remember I should probably spell out that this control is hosted inside a WinFormsControlHost in XAML. Not sure if that makes a difference but I can get at 'normal' WPF controls in my Code Behind so I'm guessing, yes. – Refracted Paladin Nov 26 '12 at 17:22

1 Answers1

36

Use x:Name instead of Name. That should do the trick.

Paweł Motyl
  • 1,304
  • 10
  • 16
  • 2
    That worked! Any chance you could, succinctly, state why? Should I ALWAYS use x:Name vs Name? – Refracted Paladin Nov 26 '12 at 17:24
  • 1
    http://stackoverflow.com/a/593151/351383 http://stackoverflow.com/a/1929978/351383 – Antonio Bakula Nov 26 '12 at 17:25
  • 5
    In a few words: `x:Name` is a XAML language feature and maps during code generation to fields in code behind. That's what gets generated in *.cs.g file during build. `Name` on the other hand is a property defined on FrameworkElement and can be handled by the control as the author pleases — it's not always mapped to the XAML `x:Name`. Some elements don't have a `Name` property. Hence, you should always use `x:Name` to name your elements for reference in XAML and code behind :) – Paweł Motyl Nov 26 '12 at 18:36