2016-09-29 97 views
0

我有下面的類:自定義類不能與X工作:綁定在UWP

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」:Property Not Found。檢查是否在平臺 的最低版本存在 您在XAML設置屬性項目(TargetPlatformMinVersion)

根據this被指定的,我不得不將Windows的最低版本,我也即:

enter image description here

我也試圖創造主體工程而不是模型項目的本地後裔,使命名空間是相同的:

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

我該怎麼辦?

+0

可能與:http://stackoverflow.com/questions/32230952/using-xbind-inside-the-gridviews-itemtemplate- layout-user-control-in-uwp – Clemens

+1

'Value'是一個被濫用的名字。爲了完全安全,請使用別的東西。也潛入代碼和錯誤,找出哪些屬性沒有找到。 –

回答

0

試試這個:

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; 
    }