简体   繁体   English

在 XAML (UWP) 中绑定单例

[英]Bind Singleton in XAML (UWP)

i try to bind the Itemsource Property of an Listview to my Singelton StaticEntryList.Instance ... How can i make this work with UWP (x:static is not available there)我尝试将 Listview 的 Itemsource 属性绑定到我的 Singelton StaticEntryList.Instance ......我如何使用 UWP 使其工作(x:static 在那里不可用)

thanks :)谢谢 :)

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()
        {

        }
        //...
    }
}

and here the MainPage.xaml这里是 MainPage.xaml

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

You just need to start the binding path with the class namespace:您只需要使用类命名空间启动绑定路径:

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

Where seproject is the namespace tag declared in the Page / UserControl root element:其中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">

This is working only if targeting (at least) Windows Anniversary update (build 14393) SDK这仅在针对(至少)Windows 周年更新(内部版本 14393)SDK 时才有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM