【问题标题】:Bind Singleton in XAML (UWP)在 XAML (UWP) 中绑定单例
【发布时间】:2018-05-04 12:41:09
【问题描述】:

我尝试将 Listview 的 Itemsource 属性绑定到我的 Singelton StaticEntryList.Instance ... 我怎样才能使这个与 UWP 一起工作(x:static 在那里不可用)

谢谢:)

namespace SE_Projekt
{
    public class StaticEntryList:List<Entry> {

        private static StaticEntryList _Instance;
        public static StaticEntryList Instance
        {
            get
            {
                if (_Instance == null) {
                    _Instance = new EntryList();
                }
                return _Instance;
            }
        }

        private StaticEntryList()
        {

        }
        //...
    }
}

这里是 MainPage.xaml

<ListView Name="StaticEntryListView" Grid.Column="0" ItemTemplate="{StaticResource StaticEntryTemplate}" ItemsSource="{x:Bind ??? :("> </ListView>

【问题讨论】:

标签: c# .net xaml uwp


【解决方案1】:

你只需要用类命名空间开始绑定路径:

<ListView Name="StaticEntryListView" 
Grid.Column="0" 
ItemTemplate="{StaticResource StaticEntryTemplate}" 
ItemsSource="{x:Bind seproject:EntryList.Instance" />

其中seproject 是在Page/UserControl 根元素中声明的命名空间标记:

<Page
  x:Class="StaticBindign.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:seproject="using:SE_Projekt"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d">

这仅适用于(至少)面向 Windows 周年更新(内部版本 14393)SDK

【讨论】:

  • 然后我收到错误“在 MainPaige 上找不到 seproject”感谢您帮助我进行编辑:我已经在使用 sepoject:在此页面的另一部分,它在那里工作正常
  • 无效的绑定路径'local:StaticEntryList.Instance':在类型'MainPage' SE-Projekt 上找不到属性'local:StaticEntryList'
  • 您至少需要针对 SDK 14393。我已经更新了答案
  • 这是问题'您至少需要针对 SDK 14393。我已经更新了答案'非常感谢
猜你喜欢
  • 2016-07-31
  • 1970-01-01
  • 2021-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-12
  • 2016-04-17
  • 1970-01-01
相关资源
最近更新 更多