我正在使用GetTemplateChild,但它总是返回NULL.如何解决这个问题?
[TemplatePart(Name = "textPoints", Type = typeof(TextBlock))]
textPoints = (TextBlock)GetTemplateChild("TextBlock");
Run Code Online (Sandbox Code Playgroud)
GetTemplateChild将名称作为参数,而不是类型。由于您的 XAML 定义为:
<TextBlock Text="{Binding}" Foreground="Cyan"
x:Name="textPoints"
Run Code Online (Sandbox Code Playgroud)
尝试传递"textPoints"而不是"TextBlock"作为要检索的名称:
[TemplatePart(Name = "textPoints", Type = typeof(TextBlock))]
textPoints = (TextBlock)GetTemplateChild("textPoints");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7378 次 |
| 最近记录: |