8,757
社区成员
发帖
与我相关
我的任务
分享
private ICollectionView _employees;
public ICollectionView Employees
{
get
{
if (_employees == null)
this._employees = CreateView(this._Context.Employees);
return _employees;
}
}
public ICollectionView CreateView(IEnumerable source)
{
CollectionViewSource cvs = new CollectionViewSource();
cvs.Source = source;
return cvs.View;
}
//……
//然后在必要的地方
Employees.GroupDescriptions.Clear();
Employees.GroupDescriptions.Add(new PropertyGroupDescription(currentSetting));
<StackPanel>
<ComboBox HorizontalAlignment="Left" Name="comboBox1" VerticalAlignment="Top" ItemsSource="{Binding GroupSettings}" SelectedItem="{Binding CurrentSetting, Mode=TwoWay}" />
<sdk:DataGrid AutoGenerateColumns="False" HorizontalAlignment="Left" ItemsSource="{Binding CollectionView}" Name="employeeDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" >
<sdk:DataGrid.Columns>
<sdk:DataGridCheckBoxColumn x:Name="applyNewNumberColumn" Binding="{Binding Path=ApplyNewNumber}" Header="Apply New Number" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="AColumn" Binding="{Binding Path=……}" Header="Apply Number" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="BColumn" Binding="{Binding Path=……}" Header="Current Number" Width="SizeToHeader" />
<sdk:DataGridTextColumn x:Name="CColumn" Binding="{Binding Path=……}" Header="Department Id" Width="SizeToHeader" />
</sdk:DataGrid.Columns>
……
</sdk:DataGrid>
</StackPanel>
public class MainPageViewModel : NotificationObject
{
private XXXDomainContext _Context = new XXXDomainContext();
private CollectionViewSource cvs;
IEnumerable<string> groupSettings;
public IEnumerable<string> GroupSettings
{
get
{
if (groupSettings == null)
groupSettings = new List<string> { "分组条件1", "分组条件2" };
return groupSettings;
}
}
private string currentSetting;
public string CurrentSetting
{
get { return currentSetting; }
set
{
if (currentSetting != value)
{
currentSetting = value;
RaisePropertyChanged(() => this.CurrentSetting);
cvs.GroupDescriptions.Clear();
cvs.GroupDescriptions.Add(new PropertyGroupDescription(currentSetting));
}
}
}
public MainPageViewModel()
{
if (!DesignerProperties.IsInDesignTool)
_Context.Load(_Context.GetXXXQuery(), lo => { CurrentSetting = "分组条件2"; }, null);
}
public ICollectionView CollectionView
{
get { return CreateView(_Context.XXX); }
}
public ICollectionView CreateView(IEnumerable source)
{
if (cvs == null)
cvs = new CollectionViewSource();
cvs.Source = source;
return cvs.View;
}