gpt4 book ai didi

c# - 如何在 C# 中访问 HubView XAML 的子元素?

转载 作者:行者123 更新时间:2023-11-30 16:55:44 30 4
gpt4 key购买 nike

我刚刚从 Windows Phone 8.1 Silverlight 迁移到 Windows Phone Store 应用程序。我有一个应用程序页面的以下 XAML:

<Page
x:Class="WebClip.HubPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WebClip"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data="using:WebClip.Data"
mc:Ignorable="d">

<Grid x:Name="LayoutRoot">
<Hub x:Name="Hub"
Header="web clip"
Background="{ThemeResource HubBackgroundImageBrush}">

<HubSection x:Name="TileSelectorView"
Header="TILE SELECTOR">
<DataTemplate>
<ListView x:Name="TileList"/>
</DataTemplate>
</HubSection>

<HubSection x:Name="BrowserView"
Header="BROWSER">
<DataTemplate>
<WebView x:Name="BrowserBox"/>
</DataTemplate>
</HubSection>

</Hub>
</Grid>
</Page>

早些时候,在 Silverlight 中,我可以直接访问像 TileList 这样的元素来执行如下操作:

TileList.ItemsSource = <SomeItemSourceList>;

但现在我无法在后端 C# 代码中执行此操作。 TileList 本身不可访问。但是,TileSelectorView 和 BrowserView(引用:上面的代码)是可访问的。

我在 Jerry 回答过类似的问题时发现了这两个问题:

  1. How to accessing Elements in XAML DataTemplate Listview without interacting with it
  2. How do I access a control inside a XAML DataTemplate?

但是,我无法复制它们。我的 TileSelectorView 下没有要迭代的 Items 属性。

我做错了什么?我该如何解决这个问题?

最佳答案

我在从 Windows Phone Silverlight 迁移到 Windows Phone RT 时遇到了同样的问题。您可以像其他人建议的那样通过数据绑定(bind)来解决这个问题,但有时您只想获得页面上的控件。我发现以下文章很有帮助..

Get the controls inside DataTemplate control

关于c# - 如何在 C# 中访问 HubView XAML 的子元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29079198/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com