将ListView绑定到C#中的winmd IObservableVector / IList [英] binding ListView to winmd IObservableVector / IList in C#

查看:70
本文介绍了将ListView绑定到C#中的winmd IObservableVector / IList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绑定到用C#构建的组件 - 其中一个类成员实现了IObservableVector:

I am trying to bind to a component built in C# - one of the class members implements IObservableVector:

< span style ="font-size:small">

public sealed class Class1
    {
        public Class1() {...}
        public String MyString { get { ...} set {...} }
        public IObservableVector<object> MyVector
        {
            get
            {
                return (IObservableVector<object>)this._myObservableVector;
            }
        }
        private MyObservableVector<object> _myObservableVector;
    }

我的HTML模板:

    <div>
        <h2 data-win-bind="textContent: myString WinJS.Binding.oneTime"></h2>
        <h2 data-win-bind="textContent: myVector WinJS.Binding.oneTime"></h2>
        <div data-win-control="WinJS.UI.ListView" data-win-bind="itemDataSource: myVector WinJS.Binding.oneTime" ></div>
</div>

和javascript代码:

and the javascript code:

    var bindingSource = null;

    app.onactivated = function (args) {
    ...
            bindingSource = WindowsRuntimeComponent.CSharp.Class1();
            args.setPromise(WinJS.UI.processAll().then(function () {
                WinJS.Binding.processAll(document.rootElement, bindingSource);
            })

前两项中的内容是正确的数据绑定,但ListView是空的。我缺少什么?我尝试了各种排列,例如切换到ObservableCollection<>并发回IList<>,通过
WinJS.Binding.as(bindingSource)等创建可绑定代理。

The content in the first two items is correctly databound, but the ListView is empty. What am I missing? I've tried all sorts of permutations like switching to an ObservableCollection<> and sending back an IList<>, creating a bindable proxy via WinJS.Binding.as(bindingSource), etc.

我找到了几个相关的论坛帖子,但都没有提供我想要的洞察力。


http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread / f53f4a19-6a32-41af-8933-2d115f2bcd24

http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/38387326-8d81-48d1-8f85-023b9ebf2382

I found a couple of related forum posts but neither provided the insight I was looking for.
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/f53f4a19-6a32-41af-8933-2d115f2bcd24
http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/38387326-8d81-48d1-8f85-023b9ebf2382

- 汤姆

推荐答案

嗨汤姆,

ListView中没有任何内容。 您必须有一个模板或自定义渲染器才能显示您绑定的内容。

You don't have anything inside your ListView.  You have to have a template or custom renderer to be show what you are binding.

请参阅ListView的快速入门,了解这些内容如何结合在一起:

See the quickstart for ListView for an intro of how this all ties together:

http://msdn.microsoft.com/en-us/library/ windows / apps / hh465496.aspx

-Jeff


这篇关于将ListView绑定到C#中的winmd IObservableVector / IList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆