<UserControl x:Class="Commands.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
             xmlns:my="clr-namespace:Commands"
             mc:Ignorable="d" d:DesignHeight="700" d:DesignWidth="700">
    <UserControl.Resources>
        <my:MyViewModel x:Key="MyViewModel"/>
        <my:TelerikGridViewCommands x:Key="telerikGridViewCommands" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" 
          Background="White" 
          DataContext="{StaticResource MyViewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <telerik:RadGridView IsSynchronizedWithCurrentItem="True" Grid.Row="0" 
                             Name="clubsGrid" 
                             ShowInsertRow="True"
                             ItemsSource="{Binding Clubs}"
                             AutoGenerateColumns="False"
                             ActionOnLostFocus="None"
                             Margin="5">
            <telerik:RadGridView.Columns>
                <telerik:GridViewColumn>
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <HyperlinkButton IsEnabled="True" Command="{Binding deleteCommand, Source={StaticResource telerikGridViewCommands}}" 
                                             CommandParameter="{Binding SelectedItem, Source={StaticResource MyViewModel}}"
                                             Content="Delete" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" />
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                            Header="Est." 
                                            DataFormatString="{}{0:yyyy}"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}" 
                                            Header="Stadium" 
                                            DataFormatString="{}{0:N0}"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <telerik:RadButton Width="150" Content="Add new row" Margin="0,0,5,0" 
							   Command="telerikGrid:RadGridViewCommands.BeginInsert" 
                               CommandTarget="{Binding ElementName=clubsGrid}"  />

            <telerik:RadButton Width="150" Content="Cancel insert/edit"
							   Command="telerikGrid:RadGridViewCommands.CancelRowEdit" 
                               CommandTarget="{Binding ElementName=clubsGrid}"  />
        </StackPanel>

    </Grid>
</UserControl>
