public class TestModel : DependencyObject { public string Test { get { return ((string)(GetValue(TestProperty))); } set { SetValue(TestProperty, value); } } /// <summary> /// Using a DependencyProperty as the backing store for BondSecurityNameForBinding. This enables animation, styling, binding, etc... /// </summary> public static DependencyProperty TestProperty = DependencyProperty.Register("Test", typeof(string), typeof(TestModel)); } 最简单的只有一个依赖属性的model,将需要展示的东西,不管是文字还是背景颜色都定义成model的属性,如果是要改变单元格颜色,在定义一个brush类型的依赖属性,比如叫Backpublic class TestModelCollection : ObservableCollection<TestModel> {}model的集合,继承ObservableCollection,可以在界面上自动更新,该集合作为绑定的集合直接作为datacontext…… <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock TextAlignment="Left" Text="{Binding Test}" Background="{Binding Back}"/> </DataTemplate> </GridViewColumn.CellTemplate> ……这是listview一列的datatemplate,将展示内容绑定,最后设置该listview的datacontext为上面的TestModelCollection,当然集合里的内容需要自己从原始数据中获取
http://www.bababagame.org
<ListView.View>
<GridView>
<GridViewColumn Width="100" DisplayMemberBinding="{Binding 0}" > <GridViewColumn Header="星期天" Width="140">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Balance}" Background="AliceBlue" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridViewColumn>
<GridViewColumn Header="星期一" Width="100" DisplayMemberBinding="{Binding 1}"/>
<GridViewColumn Header="星期二" Width="100" DisplayMemberBinding="{Binding 2}"/>
<GridViewColumn Header="星期三" Width="100" DisplayMemberBinding="{Binding 3}"/>
<GridViewColumn Header="星期四" Width="100" DisplayMemberBinding="{Binding 4}"/>
<GridViewColumn Header="星期五" Width="100" DisplayMemberBinding="{Binding 5}"/>
<GridViewColumn Header="星期六" Width="100" DisplayMemberBinding="{Binding 6}"/>
</GridView>
</ListView.View>
</ListView>
是这样吗??那个model属性加到哪里 阿
<ListView Name="lvEducation" Margin="0,0,6,139" MouseDoubleClick="lvEducation_MouseDoubleClick">
<ListView.View>
<GridView>
<GridViewColumn Header="Education" Width="0" DisplayMemberBinding="{Binding educationskey}"Style="{StaticResource backgroundcolor}"/>
</GridView>
</ListView.View>
</ListView>
在后台的绑定是
this.lvEducation.ItemsSource =dt;
注:dt中有数据,是datatable类型的
我该怎样在后台改变一个单元格的颜色啊
{
public string Test
{
get
{
return ((string)(GetValue(TestProperty)));
}
set
{
SetValue(TestProperty, value);
}
}
/// <summary>
/// Using a DependencyProperty as the backing store for BondSecurityNameForBinding. This enables animation, styling, binding, etc...
/// </summary>
public static DependencyProperty TestProperty = DependencyProperty.Register("Test", typeof(string), typeof(TestModel));
}
最简单的只有一个依赖属性的model,将需要展示的东西,不管是文字还是背景颜色都定义成model的属性,如果是要改变单元格颜色,在定义一个brush类型的依赖属性,比如叫Backpublic class TestModelCollection : ObservableCollection<TestModel>
{}model的集合,继承ObservableCollection,可以在界面上自动更新,该集合作为绑定的集合直接作为datacontext……
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock TextAlignment="Left" Text="{Binding Test}" Background="{Binding Back}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
……这是listview一列的datatemplate,将展示内容绑定,最后设置该listview的datacontext为上面的TestModelCollection,当然集合里的内容需要自己从原始数据中获取
<my:DataGrid.Columns>
<my:DataGridTextColumn Binding="{Binding 0}" Header="SUN" Width="125">
</my:DataGridTextColumn>
<my:DataGridTextColumn Binding="{Binding 1}" Header="MON" Width="125"/>
<my:DataGridTextColumn Binding="{Binding 2}" Header="TUE" Width="125"/>
<my:DataGridTextColumn Binding="{Binding 3}" Header="WED" Width="125"/>
<my:DataGridTextColumn Binding="{Binding 4}" Header="THU" Width="125"/>
<my:DataGridTextColumn Binding="{Binding 5}" Header="FRI" Width="125"/>
<my:DataGridTextColumn Binding="{Binding 6}" Header="SAT" Width="125"/>
</my:DataGrid.Columns>
</my:DataGrid>我前台就是这样
this.dg1.ItemsSource = DT_changed(year, 4).DefaultView;
Change(dg1, 4, UsersLogin.companyId, year);
this.lbOne.Content = year + "年" + 4 + "月";这是后台