【发布时间】:2015-03-17 12:34:45
【问题描述】:
我刚刚从 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 回答过类似问题的地方发现了这两个问题:
- How to accessing Elements in XAML DataTemplate Listview without interacting with it
- How do I access a control inside a XAML DataTemplate?
但是,我无法复制它们。我的 TileSelectorView 下没有 Items 属性可以迭代。
我做错了什么?我该怎么办?
【问题讨论】:
-
不要做
TileList.ItemsSource = <SomeItemSourceList>;,由binding to your data from XAML正确做。如果您还没有这样做:implement the MVVM Pattern. -
信息量很大!我正在经历它。非常感谢!
标签: c# windows-phone windows-store-apps windows-phone-8.1 winrt-xaml