我有一个模型:
public class Table : ViewModelBase
{
private int _id;
private string _north;
private string _east;
private string _south;
private string _west;
public int Id
{
get
{
return _id;
}
set
{
_id = value; OnPropertyChanged();
}
}
public string North
{
get { return _north; }
set { _north = value; OnPropertyChanged();}
}
public string East
{
get { return _east; }
set { _east = value; OnPropertyChanged();}
}
public string South
{
get { return _south; }
set { _south = value; OnPropertyChanged();}
}
public string West
{
get { return _west; }
set { _west = value; OnPropertyChanged();}
}
}
还声明了表列表的 ViewModel:
Tables = new ObservableCollection<Table>();
在 XAML 中:
<ScrollViewer.Resources>
<ItemsPanelTemplate x:Name="MyWrapPanel">
<toolkit:WrapPanel MinWidth="250" Width="{Binding ViewportWidth, ElementName=MyScrollViewer}" />
</ItemsPanelTemplate>
</ScrollViewer.Resources>
<ItemsControl ItemsSource="{Binding Tables}" ItemsPanel="{StaticResource MyWrapPanel}" Grid.RowSpan="2" Grid.Row="1">
<ItemsControl.ItemTemplate>
<DataTemplate>
<controls:TableControl
TableNumber="{Binding Id}"
North="{Binding North}"
East="{Binding East}"
South="{Binding South}"
West="{Binding West}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
但是当我将元素添加到表格列表时,一切正常。但
TableNumber="{Binding Id}"
North="{Binding North}"
East="{Binding East}"
South="{Binding South}"
West="{Binding West}"
确实不受约束。