Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid: how to bind a button #74

Open
pcdus opened this issue Sep 20, 2016 · 1 comment
Open

DataGrid: how to bind a button #74

pcdus opened this issue Sep 20, 2016 · 1 comment

Comments

@pcdus
Copy link

pcdus commented Sep 20, 2016

Hello,

I use the DataGrid with some DataGridTextColumns and a DataGridTemplatedColumn that must contain a button allowing to navigate to another page.

In code-behind, there is no problem.
But when I try to use a ViewModel implementation with a Command, it doesn't work!

The code looks like this:

<controls:DataGrid x:Name="DataGrid" Grid.Row="1"
                    ItemsSource="{Binding MyForms}"
                    SelectionMode="Single"
                    SelectedItem="{Binding SelectedForm, Mode=TwoWay}"
                    DefaultOrderIndex="1">
    <controls:DataGrid.Columns>
        <controls:DataGridTextColumn Width="0.7*" Header="Form Nr" Binding="{Binding form_id}" />
        <controls:DataGridTextColumn Width="*" Header="Submitter" Binding="{Binding submitter}" />
        ...
        <controls:DataGridTemplatedColumn Width="*" Header="Action">
            <controls:DataGridTemplatedColumn.CellTemplate>
                <DataTemplate>
                    <Button Content="Open">
                        <i:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="Tapped">
                                <core:InvokeCommandAction Command="{Binding OpenFormCommand}" />
                            </core:EventTriggerBehavior>
                        </i:Interaction.Behaviors>
                    </Button>
                </DataTemplate>
            </controls:DataGridTemplatedColumn.CellTemplate>
        </controls:DataGridTemplatedColumn>
    </controls:DataGrid.Columns>
    ...
</controls:DataGrid>

Would you have an idea?

@RicoSuter
Copy link
Owner

Do you have binging errors in your output? The context inside a column is the item not the root view model... You could bind to the parent view model via a static resource, see https://blog.rsuter.com/recommendations-best-practices-implementing-mvvm-xaml-net-applications/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants