2012-05-03 47 views
1

我正在開發一個Windows Phone 7.0的應用程序,我試圖添加一個示例設計數據文件,以便在使用Visual Studio時獲得一些圖形。 字符串或int類型正常工作,但不是自定義對象。WP7 DesignData與自定義對象

我解釋一下:

我有這樣一個類:(代表我的自定義對象)

public class CustomObject 
{ 
    public string Title { get; set; } 
} 

這是我的視圖模型:

public class MainViewModel 
{ 
    public MainViewModel() 
    { 
     this.Custom= new CustomObject(); 
     this.Custom.Title = "Hey, i'm the Runtime Custom"; 
    } 

    public CustomObject Custom{ get; set; } 

    public string TestProperty { get; set; } 
} 

我創建了一個樣本數據文件是這樣的:

<local:MainViewModel 
    xmlns:local="clr-namespace:Project.ViewModels" 
    TestProperty ="I'm the Design testProperty and I work"> 

    <local:MainViewModel.Custom Title="Hey, i'm the Design Custom, and I don't work" /> 

</local:MainViewModel> 

在我的應用程序的主頁,我已經在手機標籤中添加此:

d:DataContext="{d:DesignData SampleData.xaml}" 

好吧,當我用那樣的TestProperty變量(Text="{Binding TestProperty}")測試,它工作正常,但是當我嘗試我的對象是這樣的(Text="{Binding Custom.Title}"),它不起作用...

我發現的所有資源都無法談論自定義對象。

有沒有人有什麼想法?

坦克。

PS:我tryed添加DesignData標籤(什麼最能描述我的問題),但我不能:(

編輯: 無需編譯,Visual Studio中不顯示任何內容,我compil,它顯示Hey, i'm the Runtime Custom ......它繞過我的樣本數據文件,但僅限於該自定義對象

回答

0

嘗試稍微簡單:

<local:MainViewModel 
    xmlns:local="clr-namespace:Project.ViewModels" 
    TestProperty ="I'm the Design testProperty and I work"> 

    <local:Custom Title="Hey, i'm the Design Custom, and I don't work" /> 
</local:MainViewModel> 
+0

它不工作不幸... 當我嘗試,Visual Studio下劃線'local:Custom'並說:沒有找到類型local:Custom。 – HeyBob

1

試試這個:

<local:MainViewModel 
    xmlns:local="clr-namespace:Project.ViewModels" 
    TestProperty ="I'm the Design testProperty and I work" 
    xmlns:local2="clr-namespace:Project.NamespaceDefinitionOfTheCustomClass"> 

    <local:MainViewModel.Custom> 
     <local2:Custom Title="Hey, i'm the Design Custom, and I don't work" /> 
    </local:MainViewModel.Custom> 

</local:MainViewModel> 

如果你的類「定製」是不是在類「MainViewModel」的相同的命名空間定義,然後添加命名空間聲明像我一樣,否則只能刪除和重命名local2範圍是局部的;

它適用於我。希望爲你工作。