C# 如何在 XAML 中“创建”的代码隐藏中访问控制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13569782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access control in Code Behind that was 'created' in XAML
提问by Refracted Paladin
I have a control I 'created' in XAML that I want to access through the Code Behind.
我有一个在 XAML 中“创建”的控件,我想通过隐藏代码访问它。
<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.
但是,我在上面的第二个语句中得到了一个构建错误,说明MyApp.MainWindow does not contain a definition for 'PendingAuthsFrame1' and no extension method....它一直在运行,但你明白我猜的想法。
What am I missing or doing wrong?
我错过了什么或做错了什么?
采纳答案by Pawe? Motyl
Use x:Nameinstead of Name. That should do the trick.
使用x:Name代替Name。这应该够了吧。

