Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Items in listbox

Items in listbox

Scheduled Pinned Locked Moved WPF
question
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CrafterIt
    wrote on last edited by
    #1

    Hello, i have created a listbox that uses databinding that contains many items each item has two 2 textblock and one hyperlink button. one textblock is named ID and is Collapsed. when i press the hyperlink button i want to get the value stored in ID so i can pass it to a new Page that i open. Is this possible, and how?

    A V 2 Replies Last reply
    0
    • C CrafterIt

      Hello, i have created a listbox that uses databinding that contains many items each item has two 2 textblock and one hyperlink button. one textblock is named ID and is Collapsed. when i press the hyperlink button i want to get the value stored in ID so i can pass it to a new Page that i open. Is this possible, and how?

      A Offline
      A Offline
      Amar Chaudhary
      wrote on last edited by
      #2

      I don't know about others but I used :-

      private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
      {
      // many container controls inherit panel - so converting to panel will work in most of scenario
      ComboBox cmb = (ComboBox)((sender as Control).Parent as Panel).Children.First(x => (x as Control != null) && (x as Control).Name == "cmbShipState");
      cmb.Visibility = System.Windows.Visibility.Visible;
      }

      to find a sibling of a control on its click event. I will appreciate if somebody can show me a better way to accomplish the same. Note : The code is of different context but I think you can convert it for your scenario. :) Thanks and Regards Amar Chaudhary HBCC-Tech

      My Startup!!!!
      Profile@Elance - feedback available too

      A 1 Reply Last reply
      0
      • A Amar Chaudhary

        I don't know about others but I used :-

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
        // many container controls inherit panel - so converting to panel will work in most of scenario
        ComboBox cmb = (ComboBox)((sender as Control).Parent as Panel).Children.First(x => (x as Control != null) && (x as Control).Name == "cmbShipState");
        cmb.Visibility = System.Windows.Visibility.Visible;
        }

        to find a sibling of a control on its click event. I will appreciate if somebody can show me a better way to accomplish the same. Note : The code is of different context but I think you can convert it for your scenario. :) Thanks and Regards Amar Chaudhary HBCC-Tech

        My Startup!!!!
        Profile@Elance - feedback available too

        A Offline
        A Offline
        Abhinav S
        wrote on last edited by
        #3

        You might want to consider the command approach. Pass in the id as the command parameter.

        The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

        A 1 Reply Last reply
        0
        • A Abhinav S

          You might want to consider the command approach. Pass in the id as the command parameter.

          The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick Visit the Hindi forum here.

          A Offline
          A Offline
          Amar Chaudhary
          wrote on last edited by
          #4

          My scenario is little different as I have to show/hide few controls in row detail template of data-grid - please suggest me something for that - an attached code example would be of great value. Thanks and Regards Amar Chaudhary HBCC-Tech

          My Startup!!!!
          Profile@Elance - feedback available too

          1 Reply Last reply
          0
          • C CrafterIt

            Hello, i have created a listbox that uses databinding that contains many items each item has two 2 textblock and one hyperlink button. one textblock is named ID and is Collapsed. when i press the hyperlink button i want to get the value stored in ID so i can pass it to a new Page that i open. Is this possible, and how?

            V Offline
            V Offline
            venugopalm
            wrote on last edited by
            #5

            Hi, Its simple. Just get the data context of your hyperlink button or combobox, and get the business object property to get the actual value which you bound with textblock. Hope you can get my point.

            MVVM devotee :)

            C 1 Reply Last reply
            0
            • V venugopalm

              Hi, Its simple. Just get the data context of your hyperlink button or combobox, and get the business object property to get the actual value which you bound with textblock. Hope you can get my point.

              MVVM devotee :)

              C Offline
              C Offline
              CrafterIt
              wrote on last edited by
              #6

              Thanks for the answer, i'm new to silverlight so could you help me out to get the hiddenID value? this is my listbox with the datatemplate The listbox is loaded with many different items, the header=hyperlink does not have unique contents. What i want is to pass the current HiddenID that correspons to the hyperlink Ex: hiddenID = 34 Hyperlink = "Recent events" Content = "short description" when i press "Recent events" and trigger the hyperlinkbutton event i want to be able to get the value from hiddenID

              <ListBox x:Name="ListboxNews" ItemTemplate="{StaticResource NewsTemplate}" ItemsSource="{Binding _News}" Margin="8,38,8,8" Opacity="1" BorderThickness="0" Background="White" />

              <DataTemplate x:Key="NewsTemplate">
              <Grid Background="White" HorizontalAlignment="Left" Height="59" VerticalAlignment="Top" Width="265">
              <HyperlinkButton x:Name="NewsHyperLink" Content="{Binding Header}" FontSize="18.667" FontWeight="Bold" FontFamily="/StartPage;component/Fonts/Fonts.zip#Calibri" Click="HyperlinkButton_Click" Background="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" d:LayoutOverrides="HorizontalAlignment, VerticalAlignment" Margin="10,0,0,0"/>
              <TextBlock x:Name="Content" Text="{Binding Content}" TextWrapping="Wrap" Width="265" FontFamily="/StartPage;component/Fonts/Fonts.zip#Calibri" FontSize="16" Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="12,23,0,0" />
              <TextBlock x:Name="HiddenID" Text="{Binding NewsID}" Width="20" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment" FontSize="16" HorizontalAlignment="Left" Margin="-2,0,0,0" />
              </Grid>
              </DataTemplate>

              V 1 Reply Last reply
              0
              • C CrafterIt

                Thanks for the answer, i'm new to silverlight so could you help me out to get the hiddenID value? this is my listbox with the datatemplate The listbox is loaded with many different items, the header=hyperlink does not have unique contents. What i want is to pass the current HiddenID that correspons to the hyperlink Ex: hiddenID = 34 Hyperlink = "Recent events" Content = "short description" when i press "Recent events" and trigger the hyperlinkbutton event i want to be able to get the value from hiddenID

                <ListBox x:Name="ListboxNews" ItemTemplate="{StaticResource NewsTemplate}" ItemsSource="{Binding _News}" Margin="8,38,8,8" Opacity="1" BorderThickness="0" Background="White" />

                <DataTemplate x:Key="NewsTemplate">
                <Grid Background="White" HorizontalAlignment="Left" Height="59" VerticalAlignment="Top" Width="265">
                <HyperlinkButton x:Name="NewsHyperLink" Content="{Binding Header}" FontSize="18.667" FontWeight="Bold" FontFamily="/StartPage;component/Fonts/Fonts.zip#Calibri" Click="HyperlinkButton_Click" Background="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" d:LayoutOverrides="HorizontalAlignment, VerticalAlignment" Margin="10,0,0,0"/>
                <TextBlock x:Name="Content" Text="{Binding Content}" TextWrapping="Wrap" Width="265" FontFamily="/StartPage;component/Fonts/Fonts.zip#Calibri" FontSize="16" Foreground="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="12,23,0,0" />
                <TextBlock x:Name="HiddenID" Text="{Binding NewsID}" Width="20" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment" FontSize="16" HorizontalAlignment="Left" Margin="-2,0,0,0" />
                </Grid>
                </DataTemplate>

                V Offline
                V Offline
                venugopalm
                wrote on last edited by
                #7

                Hi, Here is the Click Event handler which i said private void Link1_Click(object sender, RoutedEventArgs e) { string id= ((sender as HyperlinkButton).DataContext as YourBusineesObject).HiddenID; } Let me know if this works.

                MVVM devotee :)

                C 1 Reply Last reply
                0
                • V venugopalm

                  Hi, Here is the Click Event handler which i said private void Link1_Click(object sender, RoutedEventArgs e) { string id= ((sender as HyperlinkButton).DataContext as YourBusineesObject).HiddenID; } Let me know if this works.

                  MVVM devotee :)

                  C Offline
                  C Offline
                  CrafterIt
                  wrote on last edited by
                  #8

                  Hi! Yes, i got it working, many thanks !!! :)

                  V 1 Reply Last reply
                  0
                  • C CrafterIt

                    Hi! Yes, i got it working, many thanks !!! :)

                    V Offline
                    V Offline
                    venugopalm
                    wrote on last edited by
                    #9

                    Great. Enjoy :-D

                    MVVM devotee :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups