locked
Problem in passing command Parameter inside GridView of windows store apps RRS feed

  • Question

  • Hi Team,

    I am developing a tablet application where in I have a grid view which is bind to a collection. I have a hyperlinkbuttoon where in I have attached a command property to the same. If I click on hyperlink on any item of list , a popup should appear with the parameter as a name from the selected item. The problem is am able to invoke the command in the view model but am not able to pass parameter of the selected item. here is my code

                 <GridView
                x:Name="ItemGridView"
                AutomationProperties.AutomationId="ItemGridView"   
                ItemsSource="{Binding OtherAcceptableOils}"
                SelectionMode="Single"
                ScrollViewer.HorizontalScrollBarVisibility="Hidden"
                    SelectedItem="{Binding SelectedOil,Mode=TwoWay}">
                                   <GridView.ItemTemplate>
     <DataTemplate >
                        
    <TextBlock  Text="{Binding property1}">
    <TextBlock Text="{BindingProperty2" />                                <HyperlinkButton   Content="Confirm" Command="{Binding DataContext.MoreInfo,ElementName=ItemGridView}" CommandParameter="{Binding ElementName=ItemGridView,Path=SelectedOil}"/>
                                                     </DataTemplate>
                    </GridView.ItemTemplate>
                </GridView>

    AND ViewModel Code goes here

    public class myclass

    {

    private Command moreInfo;
    public Command MoreInfo { get { return moreInfo; } }

    public myclass(){

    moreInfo = new Command(showpopup);

    }

    public void showpopup

    {//code to show popup//I want my propert values of the selected item when I click the hyperlink of item

    }

    }

    I have all the properties which am not showing here . I am able to bind the list and properties inside list are getting populated

    public class Command: BaseCommand
        {
            private readonly Action _execute;
            private readonly Func<bool> _canExecute;
    
            /// <summary>
            /// Initializes a new instance of the <see cref="Command"/> class.
            /// </summary>
            /// <param name="execute">The execute.</param>
            /// <param name="canExecute">The can execute.</param>
            /// <exception cref="System.ArgumentNullException">execute</exception>
            public Command(Action execute, Func<bool> canExecute = null)
            {
                if (execute == null) throw new ArgumentNullException("execute");
    
                _execute = execute;
                _canExecute = canExecute;
            }
    
            /// <summary>
            /// Defines the method that determines whether the command can execute in its current state.
            /// </summary>
            /// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>
            /// <returns>
            /// true if this command can be executed; otherwise, false.
            /// </returns>
            public override bool CanExecute(object parameter)
            {
                return _canExecute == null || _canExecute();
            }
    
            /// <summary>
            /// Defines the method to be called when the command is invoked.
            /// </summary>
            /// <param name="parameter">Data used by the command.  If the command does not require data to be passed, this object can be set to null.</param>
            public override void Execute(object parameter)
            {
                if (CanExecute(parameter))
                {
                    _execute();
                }
            }
        }

    Please propose any solution for this which helps me a lot











           



    Purushothama V S

    Wednesday, July 22, 2015 1:34 PM