Results 1 to 2 of 2

Thread: WPF Selected Item

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Location
    Milan
    Posts
    810

    WPF Selected Item

    I have this data template in my wpf xaml to add items to my listbox.

    How can I via VB.NET code access the Caty_Name when one is selected?

    wpf Code:
    1. <DataTemplate x:Key="Caty" x:Name="CatyItem">
    2.             <Border Background="White" BorderBrush="Black" BorderThickness="2" CornerRadius="15" Padding="10px" Margin="5px">
    3.                 <Grid>
    4.                 <Grid.RowDefinitions>
    5.                     <RowDefinition></RowDefinition>
    6.                     <RowDefinition></RowDefinition>
    7.                     <RowDefinition Height="3px"></RowDefinition>
    8.                 </Grid.RowDefinitions>
    9.                 <Grid.ColumnDefinitions>
    10.                     <ColumnDefinition Width="30px"></ColumnDefinition>
    11.                     <ColumnDefinition Width="200px"></ColumnDefinition>
    12.                 </Grid.ColumnDefinitions>
    13.  
    14.                     <TextBlock Grid.Column="1" Grid.Row="0" Margin="2" Foreground="Black" Text="{Binding Path=Name}"></TextBlock>
    15.                 <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1" Margin="2">
    16.                     <TextBlock Foreground="Black" x:Name="Caty_ID" Text="Catalogue ID:"></TextBlock>
    17.                         <TextBlock Foreground="Black" x:Name="Caty_Name" Text="{Binding Path=CatalogueID}"></TextBlock>
    18.                 </StackPanel>
    19.                     <Image Grid.RowSpan="2" Grid.Column="0" Grid.Row="0" Height="30px" Width="30px"  Source="catalog.gif"></Image>
    20.                
    21.             </Grid>
    22.             </Border>
    23.         </DataTemplate>

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611

    Re: WPF Selected Item

    Use should use databinding. In the code-file, you should create a property:
    Code:
    Public Property SelectedPRP As myClass
    And in the xaml-file:

    <Listbox ItemsSource = "{Binding bla}" SelectedItem="{Binding SelectedPRP}"/>

    SelectedPRP machtes the selected item in the listbox. If no item is selected, SelectedPRP = Nothing
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width