C# 使用Caliburn Micro绑定Xceed DataGridControl
我想用Caliburn Micro绑定一个Xceed DataGridControl。设置绑定的最佳方法是什么?我想在视图模型中使用Caliburn样式的方法,而不使用ICommand。在网格中按Enter键或双击时,它应该调用方法C# 使用Caliburn Micro绑定Xceed DataGridControl,c#,caliburn.micro,xceed-datagrid,C#,Caliburn.micro,Xceed Datagrid,我想用Caliburn Micro绑定一个Xceed DataGridControl。设置绑定的最佳方法是什么?我想在视图模型中使用Caliburn样式的方法,而不使用ICommand。在网格中按Enter键或双击时,它应该调用方法OpenContract(Contract c) 视图: 视图模型: public class ContractViewModel : Screen { public BindableCollection<Contract> Contracts
OpenContract(Contract c)
视图:
视图模型:
public class ContractViewModel : Screen
{
public BindableCollection<Contract> Contracts { get; private set; }
private ContractRepository _repository;
public ContractViewModel(ContractRepository repository)
{
_repository = repository
}
public async void OnViewLoaded()
{
Contracts.Clear();
Contracts.AddRange(_repository.GetAll());
}
public IEnumerable<IResult> OpenContract(Contract contract)
{
yield return;
}
}
公共类合同视图模型:屏幕
{
公共BindableCollection约定{get;private set;}
私有合同存储库(U存储库);;
公共ContractViewModel(ContractRepository存储库)
{
_存储库=存储库
}
public异步void OnViewLoaded()
{
合同;
Contracts.AddRange(_repository.GetAll());
}
公共IEnumerable OpenContract(合同)
{
收益率;
}
}
结果表明,可以使用caliburn进行绑定:
你看过维基了吗?写Caliburn Micro的人也在Xceed datagrid上工作,所以他就是要问的人:)
public class ContractViewModel : Screen
{
public BindableCollection<Contract> Contracts { get; private set; }
private ContractRepository _repository;
public ContractViewModel(ContractRepository repository)
{
_repository = repository
}
public async void OnViewLoaded()
{
Contracts.Clear();
Contracts.AddRange(_repository.GetAll());
}
public IEnumerable<IResult> OpenContract(Contract contract)
{
yield return;
}
}
<xcdg:DataGridControl ItemsSource="{Binding Contracts}" AutoCreateColumns="False">
<xcdg:DataGridControl.Resources>
<Style TargetType="{x:Type xcdg:DataCell}">
<Setter Property="cal:Message.Attach" Value="[Event PreviewMouseDoubleClick] = [Action OpenContract($this)]" />
</Style>
</xcdg:DataGridControl.Resources>
<xcdg:DataGridControl.View>
<xcdg:TableView AllowColumnChooser="True" ShowFixedColumnSplitter="False" AllowRowResize="False" ShowRowSelectorPane="False" UseDefaultHeadersFooters="False" ColumnStretchMode="Last">
<xcdg:TableView.FixedHeaders>
<DataTemplate>
<xcdg:ColumnManagerRow AllowColumnReorder="True" AllowSort="True" AllowColumnResize="True" AllowAutoFilter="False" />
</DataTemplate>
</xcdg:TableView.FixedHeaders>
</xcdg:TableView>
</xcdg:DataGridControl.View>
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="Name" Title="Name"></xcdg:Column>
<xcdg:Column FieldName="CustomerName" Title="Customer"></xcdg:Column>
</xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>