Items in listbox
-
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?
-
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?
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
-
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
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.
-
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.
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
-
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?
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 :)
-
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 :)
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> -
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>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 :)
-
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 :)
-
Great. Enjoy :-D
MVVM devotee :)