0
我想将Xceed DataGridControl与Caliburn Micro绑定。什么是设置绑定的最佳方式,我想在我的视图模型中使用没有ICommands的Caliburn样式方法。在输入密钥或双击网格中,它应该调用方法OpenContract(Contract c)
。将Xceed DataGridControl与Caliburn Micro绑定
查看:
<xcdg:DataGridControl ItemsSource="{Binding Contracts}" AutoCreateColumns="False">
<xcdg:DataGridControl.InputBindings>
<KeyBinding Key="Enter" Command="{Binding Path=OpenContractCommand}" CommandParameter="{Binding ElementName=DataGrid, Path=SelectedItems}"/>
<MouseBinding MouseAction="LeftDoubleClick" Command="{Binding Path=OpenContractCommand}" CommandParameter="{Binding ElementName=DataGrid, Path=SelectedItems}"/>
</xcdg:DataGridControl.InputBindings>
<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>
视图模型:
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;
}
}
你已经采取了看看[所有关于操作](https://caliburnmicro.codeplex.com/wikipage?title=All%20About%20Actions&referringTitle=Documentation)Wiki。 –