質問

I want to bind an Xceed DataGridControl with Caliburn Micro. What is the best way to setup the binding, I want to use the Caliburn style methods without ICommands in my view model. On Enter-Key or double click in the grid it should call the method OpenContract(Contract c).

View:

<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>

ViewModel:

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;
    }
}
役に立ちましたか?

解決

Turns out the binding can be done with caliburn (see this discussion):

<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>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top