积极答复者
怎么作控件互动的效果?

问题
答案
-
你好,
下面是代码. TextBlock绑到第一个对象:
public MainPage()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{Customer c = new Customer { age = i };
array.Add(c);
}this.DataGrid1.ItemsSource = array;
this.testTextBlock.DataContext = array[0];
}
public class Customer : INotifyPropertyChanged
{
#region INotifyPropertyChanged Memberspublic event PropertyChangedEventHandler PropertyChanged;
private int _age;
public int age
{
get { return _age; }
set
{
_age = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("age"));
}
}
}#endregion
}
<TextBlock x:Name="testTextBlock" Text="{Binding age}"></TextBlock>
<data:DataGrid AutoGenerateColumns="False" Width="500" Height="500" x:Name="DataGrid1">
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Width="80">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding age}"></TextBlock>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding age, Mode=TwoWay}"></TextBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn></data:DataGrid.Columns>
</data:DataGrid>
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Need a sample of a technique of Microsoft? Just check out CodeFx first! http://cfx.codeplex.com/- 已标记为答案 Silverlighter 2009年8月25日 17:28
2009年8月24日 7:21
全部回复
-
你好,
下面是代码. TextBlock绑到第一个对象:
public MainPage()
{
InitializeComponent();
for (int i = 0; i < 10; i++)
{Customer c = new Customer { age = i };
array.Add(c);
}this.DataGrid1.ItemsSource = array;
this.testTextBlock.DataContext = array[0];
}
public class Customer : INotifyPropertyChanged
{
#region INotifyPropertyChanged Memberspublic event PropertyChangedEventHandler PropertyChanged;
private int _age;
public int age
{
get { return _age; }
set
{
_age = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("age"));
}
}
}#endregion
}
<TextBlock x:Name="testTextBlock" Text="{Binding age}"></TextBlock>
<data:DataGrid AutoGenerateColumns="False" Width="500" Height="500" x:Name="DataGrid1">
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Width="80">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding age}"></TextBlock>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding age, Mode=TwoWay}"></TextBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn></data:DataGrid.Columns>
</data:DataGrid>
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Need a sample of a technique of Microsoft? Just check out CodeFx first! http://cfx.codeplex.com/- 已标记为答案 Silverlighter 2009年8月25日 17:28
2009年8月24日 7:21