<GridView AllowsColumnReorder="False">
<GridViewColumn Header="Tên Mặt Hàng" CellTemplate="{StaticResource Ten}">
<GridViewColumn.CellTemple>
<DataTemplate x:Key="Ten">
<TextBlock Text="{Binding Ten}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemple>
</GridViewColumn> </GridView>
各位,我有代码,我想绑定(bind)textBlock的Text,以便在其他文件中再次使用数据,那我该怎么办?
最佳答案
您可以创建此 View 的 ViewModel。并将 viewModel 属性绑定(bind)到该 View 。例如:
public class NamViewModel: INotifyPropertyChanged {
private string _ten;
public string Ten {
get
{
return _ten;
}
set
{
_ten = value;
this.RaisePropertyChanged("Ten");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName) {
if (PropertyChanged != null) {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
然后你可以在 View 的构造函数中绑定(bind)这个viewModel。例如:
public partial class NamView : Window {
public NamView() {
InitializeComponent();
this.DataContext = new NamViewModel();
}
}
关于c - celltemp结合数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53679487/