UWP ButtonColumn MvvmLight / Telerik / WindowsTemplate Studio

45 Views Asked by At

I´m trying to add a ButtonColumn to a TelerikDataGrid which was generated by the Windows Template Studio, without CodeBehind. In a perfect world it would work like this, I think.

<tg:DataGridTemplateColumn x:Uid="Table_Open" >
    <tg:DataGridTemplateColumn.CellContentTemplate >
        <DataTemplate>
            <Button x:Uid="Button_Open" Command="{x:Bind ViewModel.OpenCustomerCommand}"></Button>
            </DataTemplate>
    </tg:DataGridTemplateColumn.CellContentTemplate>
</tg:DataGridTemplateColumn>

This doesn't work, now I tried many opportunities but never reach the ViewModel. I know in WPF it would work using

RelativeSource={RelativeSource AncestorType={x:Type UserControl},

But I don't get it reproduced in my UWP case.

1

There are 1 best solutions below

6
Nico Zhu On

I'm afraid you can't use x:bind to bind OpenCustomerCommand in DataTemplate, In general, if we want to bind viewmodel's OpenCustomerCommand we need set current Page DataContext as ViewModel then use binding markup extension to bind like the following.

<Button HorizontalAlignment="Right" 
    Margin="0,0,30,0" 
    Content="Favorite" 
    Command="{Binding ElementName=RootGrid,Path=DataContext.OpenCustomerCommand }" 
       />

And this is the similar case that your could refer.