无法从类访问hub元素 [英] Can't access hub elements from class
本文介绍了无法从类访问hub元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在主页上有一个xaml,想要在ac#类中访问它的元素x:Name =D1P1但不能使用它并得到一个错误,当前上下文中不存在名称D1P1想法如何访问c#类中的hub元素我使用FindName但它不起作用
I had a xaml in mainpage and want to access it's elements like x:Name="D1P1" in a c# class but can't use it and get an error the name "D1P1" does not exist in the current context any idea how to access the hub elements in c# class I use FindName but it did't work
<HubSection Width="950" x:Name="DayOneTimeHubSection" Margin="20,0,0,0">
<DataTemplate>
<Grid>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Height="180" Margin="0,0,0,-15">
<StackPanel Width="280" Height="160" Background="#FF253842" Margin="05,0,0,0">
<TextBlock x:Name="D1P1" HorizontalAlignment="Center" LineHeight="80" TextWrapping="Wrap" FontSize="64" TextAlignment="Center" Foreground="#FFB0B1B2" FontFamily="Arial Narrow" Margin="0,10,0,0" />
<TextBlock x:Name="D1NP1" HorizontalAlignment="Center" VerticalAlignment="Bottom" LineHeight="64" TextWrapping="Wrap" FontSize="64" TextAlignment="Center" Foreground="White" FontFamily="DengXian" Margin="30,0" />
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</hubsection>
推荐答案
您无法访问集线器部分内的控件,因为它们位于数据模板中。如果你使用MVVM,你可以绑定数据。
You cannot access controls inside a hub section as because they were inside a data template. if you use MVVM you can bind the data.
这篇关于无法从类访问hub元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文