Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3562
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T19:15:51+00:00 2022-06-02T19:15:51+00:00

wpf – get selected item from Grid ListView

  • 0

[ad_1]

I just followed this tutorial https://www.youtube.com/watch?v=_4qej7q6x30 on how to create a Responsive Horizontal ListView, the problem is that I don’t know how to get the selected item to run specific code.

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
            
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="170"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <ScrollViewer Grid.Column="1" Grid.Row="1">
            <StackPanel>
                <TextBlock Text="Games" FontSize="40" Foreground="White" TextAlignment="Center"/>
                <StackPanel Margin="10 0">
                    <ItemsControl x:Name="games_list" ItemsSource="{Binding games}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Border Margin="10" Width="128" Height="128">
                                    <StackPanel>
                                        <Border  Width="100" Height="100" CornerRadius="25" Margin="5">
                                            <Border.Background>
                                                <ImageBrush ImageSource="{Binding Image_path}"/>
                                            </Border.Background>
                                        </Border>
                                        <TextBlock Text="{Binding Name}" Foreground="White" TextAlignment="Center" />
                                    </StackPanel>
                                </Border>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapPanel/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </StackPanel>
            </StackPanel>
        </ScrollViewer>
    </Grid>

This is my grid. It works as it should but I don’t know how to check which item I clicked, I need it to run

            var item = ???;
            if (item != null)
            {
                try
                {
                    GameTemplate game = ((GameTemplate)item);
                    ProcessStartInfo processStartInfo = new ProcessStartInfo();
                    processStartInfo.FileName = game.Run_command;
                    if (game.Run_arguments != null)
                        processStartInfo.Arguments = $"\"{game.Run_arguments}\"";
                    Process.Start(processStartInfo);
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(ex.Message);
                    sb.AppendLine();
                    sb.AppendLine(ex.StackTrace);
                    sb.AppendLine();
                    sb.AppendLine(ex.Source);
                    MessageBox.Show(sb.ToString());
                }
            }

This casts the item to a custom class with specific values

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8087 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1871 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1957 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.