如果在 WPF 我有这个代码:
using System.Collections.ObjectModel;
...
...
public partial class MainWindow : Window
{
public ObservableCollection<String> myMatrixData = new ObservableCollection<String>();
public MainWindow()
{
InitializeComponent();
int i;
for (i = 0; i < 100; i++)
myMatrixData.Add("Test");
myMatrix.ItemsSource = myMatrixData;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Cell00.Text = myMatrixData[0];
}
}
XAML:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
...
...
<Grid>
<StackPanel>
<ItemsControl x:Name="myMatrix">
<ItemsControl.Resources>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<!-- specify the panel that is the container for the items -->
<ItemsPanelTemplate>
<UniformGrid Rows="10" Columns="10" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!-- specify the template used to render each item -->
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type sys:String[]}">
<TextBox Text="{Binding Path=., UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Button Content="Read cell 0/0" Click="Button_Click_1"/>
<TextBlock x:Name="Cell00"/>
</StackPanel>
</Grid>
我只想反映ObservableCollection myMatrixData
要反映在一个名为的UniformGrid
样式中的元素。更改第一个单元格中的文本并按下按钮表明这不起作用。ItemsControl
myMatrix
我错过了什么?