【问题标题】:Custom class not working with x:Bind in UWP自定义类不适用于 UWP 中的 x:Bind
【发布时间】:2017-02-07 14:29:05
【问题描述】:

我有以下课程:

namespace MainProject.Model
{
   public class ModelObject: INotifyPropertyChanged
   {
     public int Value{ get; set; }
   }
}

我尝试在我的模板中使用它x:Bind

 <DataTemplate x:Key="ListViewItemTemplate" x:DataType="model:ModelObject">
    <my:CustomSelector Grid.Column="1" ActualValue="{x:Bind Value}" />
</DataTemplate>

在构建时我总是收到以下消息:

XBF 语法错误“0x09C4”:找不到属性。检查属性是否 您在 XAML 中设置的存在于平台的最低版本中 在项目中指定(TargetPlatformMinVersion)

根据this,我必须设置Windows的最低版本,我做到了:

我还尝试在主项目而不是模型项目中创建本地后代以使命名空间相同:

namespace MainProject.UWP
  {
       public class UWPModelObject: ModelObject
      {
      }
  }

我还应该做什么?

【问题讨论】:

  • Value 是一个过度使用的名称。为了完全安全,请使用其他东西。还要深入研究代码和错误以找出未找到的属性。

标签: uwp xamarin.uwp


【解决方案1】:

试试这个:

public class ModelObject : INotifyPropertyChanged
{
    public int DaValue
    {
        get { return _daValue; }
        set
        {
            _daValue = value;
            OnPropertyChanged();
        }
    }

    private int _daValue;




    public event PropertyChangedEventHandler PropertyChanged;


    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

int 是正确的类型吗?还是应该使用字符串!?

编辑:在 MainPage.cs 中设置 datacontext 如下:

public MainPage()
    {
        this.InitializeComponent();
        ModelObject modelObject = new ModelObject();
        DataContext = modelObject;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-17
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    相关资源
    最近更新 更多