大佬教程收集整理的这篇文章主要介绍了win10 uwp xaml 绑定接口,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
本文告诉大家如何在 xaml 绑定属性使用显式继承接口
早上快乐 就在你的心问了我一个问题,他使用的属性是显式继承,但是无法在xaml绑定
public class Foo : INotifyPropertyChanged,if1
{
public Foo(String Name)
{
_name = name;
}
private String _name;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] String propertyName = null)
{
PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(propertyName));
}
String if1.Name
{
get { return _name; }
set { _name = value; OnPropertyChanged(); }
}
}
public interface if1
{
String Name { set; get; }
}
public ObservableCollection<Foo> Foo { set; get; } = new ObservableCollection<Foo>()
{
new Foo("jlong"){}
};
<ListView Itemssource="{x:Bind Foo}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:Foo">
<TextBlock Text="{Binding Path=Name }"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
但是这样写出现绑定错误,因为在 Foo 是找不到 Name 属性,需要使用 if1.Name 去拿到
<TextBlock Text="{Binding (local:if1.Name)}"></TextBlock>
但是运行就出现了异常,说未指定,最后我尝试了新的方法,居然就编译通过,下面让我来告诉大家如何使用这个方法
<TextBlock Text="{x:Bind Path=(local:if1.Name) }"></TextBlock>
如果使用显式继承,那么在使用的时候需要使用他的接口来拿,但是接口不是直接写,需要先写空间,一般空间是写在最上,请看下面代码
<Page
x:Class="JoleenOneal.MainPage"
xmlns="http://scheR_953_11845@as.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://scheR_953_11845@as.microsoft.com/winfx/2006/xaml"
xmlns:local="using:JoleenOneal" 这是空间
xmlns:d="http://scheR_953_11845@as.microsoft.com/expression/blend/2008"
xmlns:mc="http://scheR_953_11845@as.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
然后需要加上括号,才可以使用
我找到了下面的观点
本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。欢迎转载、使用、重新发布,但务必保留文章署名林德熙(包含链接:http://blog.csdn.net/lindexi_gd ),不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系。
以上是大佬教程为你收集整理的win10 uwp xaml 绑定接口全部内容,希望文章能够帮你解决win10 uwp xaml 绑定接口所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。