-
Mar 10th, 2012, 03:59 PM
#1
Thread Starter
Fanatic Member
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:
<DataTemplate x:Key="Caty" x:Name="CatyItem">
<Border Background="White" BorderBrush="Black" BorderThickness="2" CornerRadius="15" Padding="10px" Margin="5px">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="3px"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30px"></ColumnDefinition>
<ColumnDefinition Width="200px"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="1" Grid.Row="0" Margin="2" Foreground="Black" Text="{Binding Path=Name}"></TextBlock>
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1" Margin="2">
<TextBlock Foreground="Black" x:Name="Caty_ID" Text="Catalogue ID:"></TextBlock>
<TextBlock Foreground="Black" x:Name="Caty_Name" Text="{Binding Path=CatalogueID}"></TextBlock>
</StackPanel>
<Image Grid.RowSpan="2" Grid.Column="0" Grid.Row="0" Height="30px" Width="30px" Source="catalog.gif"></Image>
</Grid>
</Border>
</DataTemplate>
-
Mar 11th, 2012, 01:50 PM
#2
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|