【发布时间】:2014-10-24 19:16:14
【问题描述】:
我的 Windows Phone 8.1 项目中的绑定有问题,而不是 silverlight。
我有一个简单的 ViewModel,其中包含一个 ObservableCollection 和一个 int。
如果我使用设计器创建绑定,我只能看到int 属性。
我正在尝试绑定到 ItemsControl 的 ItemsSource 属性
因此,据我所知,除了用于绑定的Collection or List 之外,它应该是。
但我只看到这个:
我错过了什么吗?
这应该是可能的。
MainPage.xaml
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Nice_Dice"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:uc="using:Nice_Dice"
xmlns:vm="using:Nice_Dice.ViewModel"
x:Class="Nice_Dice.MainPage"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.DataContext>
<vm:Dices/>
</Page.DataContext>
<ScrollViewer>
<ItemsControl x:Name="Test" ItemsSource="HERE IS WHERE I TRY TO BIND">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Page>
Dices.cs (ViewModel)
public class Dices
{
public ObservableCollection<Outcome> Outcomes = new ObservableCollection<Outcome>();
public IList<string> Test;
public int MyProperty { get; set; }
public Dices()
{
MakeTestData();
}
public void MakeTestData()
{
Dice a = new Dice
{
Name = "D6",
States = new ObservableCollection<State>
{
new State
{
Value = "1"
},
new State
{
Value = "2"
},
new State
{
Value = "3"
},
new State
{
Value = "4"
},
new State
{
Value = "5"
},
new State
{
Value = "6"
}
}
};
a.States[5].Dice = a;
for (int i = 0; i <= 99; i++)
Outcomes.Add(a.GetOutcome());
}
}
【问题讨论】:
标签: c# wpf xaml mvvm windows-phone-8.1