LucKy_one

Always aiming higher


  • 首页

  • 关于

  • 标签

  • 分类

  • 归档

  • 搜索

访问HubSection中的ListView(windows 8)

发表于 2014-07-28 更新于 2016-10-03
首先一条特别重要的是:在HubSection中的控件是无法在代码中直接访问的。

首先一条特别重要的是:
在HubSection中的控件是无法在代码中直接访问的。

<HubSection Width="800" x:Uid="Section1Header" Header="Header">
    <DataTemplate>
        <ListView x:Name="listview">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" >
                        <TextBox Text="{Binding text}"/>
                    </StackPanel>
                     </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </DataTemplate>
</HubSection>

这样一个ListView如果你像平常一样在代码里

listView.ItemsSource = someObservableCollection;

会报错The name ‘listView’ does not exist in the current context

一个非常简单的解决办法是在ListView里添加Loaded事件函数。

<ListView x:Name="listview" Loaded="ListView_Loaded">

然后添加函数

private void NotificationList_Loaded(object sender, RoutedEventArgs e)
{
    var listView = (ListView)sender;
     listView.ItemsSource = someObservableCollection;
}

总感觉应该有更好的方法。

# windows8开发
向Windows8应用推送通知(Toast)并响应点击通知事件
java实现多继承(转载)

Liu Tianhe

喜欢金融,喜欢科技
31 日志
29 标签
RSS
GitHub E-Mail
© 2014 – 2022 Liu Tianhe
由 Hexo 强力驱动 v3.9.0
|
主题 – NexT.Mist v7.3.0