I fill my LongListSelector with this template:
<DataTemplate x:Key="LongListSelectorItemTemplate">
<StackPanel Orientation="Horizontal" Margin="4,4">
<Grid Tap="Grid_Tap" x:Uid="{Binding Id}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Grid.RowSpan="3" Width="150" Height="60" Source="{Binding Logo}" VerticalAlignment="Center" Margin="0,0,15,0"/>
<TextBlock Grid.Column="1" Text="{Binding NazwaSklepu}" FontFamily="/Okazjum;component/Fonts/Fonts.zip#Open Sans" VerticalAlignment="Center" HorizontalAlignment="Left" Foreground="Black" FontSize="32"/>
<Image Grid.Column="1" Grid.Row="1" Source="1.0_Images/Vector Smart Object.png" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding GodzinyOtwarcia}" FontFamily="/Okazjum;component/Fonts/Fonts.zip#Open Sans Light" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="14" Foreground="Gray" Margin="25,0,0,0" />
<Image Grid.Column="1" Grid.Row="2" Source="1.0_Images/Vector Smart Object copy 3.png" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Adres}" FontFamily="/Okazjum;component/Fonts/Fonts.zip#Open Sans Light" VerticalAlignment="Center" HorizontalAlignment="Stretch" FontSize="14" Foreground="Gray" Margin="25,0,0,0" x:Name="txtAdres"/>
</Grid>
</StackPanel>
</DataTemplate>
As you can see I added Tap event to my grid and Binding id.
How can I obtain this Id in my C# event code?
I found temporary way. I put Id in Tag instead of x:Uid
and used following code:
private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
int id = -1;
var element = (FrameworkElement)sender;
if (int.TryParse((Grid)element.Tag + "", out id)) {
... my code
}
}
Related
I made a list , and my need is to be able to make click ( touch ) the user across the row , when clicked I should be able to pass the 'mid' to event , I hid in the code to pick it up then at the click of that record.
It's possible ?
<Grid Grid.Row="1" Grid.ColumnSpan="2">
<ScrollViewer VerticalScrollBarVisibility="Hidden" PanningMode="Both">
<ItemsControl ItemsSource="{Binding Path=NextMeetingList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Grid.Column="0" Grid.Row="0">
<Border Grid.Column="0" Grid.Row="0" Margin="10" Height="60" Background="GhostWhite" CornerRadius="3" BorderBrush="{Binding BorderColor}" BorderThickness="0,8,0,0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="118"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="40" Margin="10,5,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding endDate.Day}"/>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="12" Margin="77,13,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text="{Binding DayString}"/>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="70,26,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text="{Binding endDate.Hour}"/>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="86,26,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text=":"/>
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" FontSize="14" Margin="90,26,0,0" Height="Auto" Style="{DynamicResource Lato-Semibold}" Text="{Binding MinuteString}"/>
<Border Grid.Row="0" Grid.Column="0" Width="1" BorderBrush="#BABABA" Height="40" Margin="115,-6,0,0" BorderThickness="1" HorizontalAlignment="Left"></Border>
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" Text="{Binding subject}" FontWeight="Bold" FontSize="17" Margin="10,10,0,0"/>
<TextBlock Grid.Row="0" Grid.Column="1" Width="Auto" TextWrapping="Wrap" HorizontalAlignment="Left" Text="{Binding descr}" FontSize="10" Margin="20,27,150,0"/>
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Text="{Binding companyName}" FontSize="10" Margin="0,10,30,0"/>
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Text="{Binding Location}" FontSize="10" Margin="0,27,30,0"/>
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Text=">" FontSize="15" VerticalAlignment="Center" Margin="0,-5,10,0"/>
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Right" Text="{Binding mid}" Visibility="Hidden" FontSize="15" VerticalAlignment="Center" Margin="0,-5,10,0"/>
</Grid>
</Border>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
A possible solution is to wrap your content in an invisible button and passing the id or the entire object as CommandParameter to a Command on the ViewModel.
<Button Command="{Binding DataContext.MyCommmand, ElementName=mainGrid}"
CommandParameter="{Binding}">
<!-- Content -->
</Button>
Typically if I want to handle a Click event of anything I just use a Button and overwrite the .Template of it.
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Template="{StaticResource ContentOnlyTemplate}"
CommandParameter="{Binding mid}"
Click/Command=...>
<StackPanel Grid.Column="0" Grid.Row="0">
...
</StackPanel>
</Button>
</DataTemplate>
</ItemsControl>
WPF controls are meant to be "lookless", so a Button control is ideal in this case because it contains the functionality to handle Click and/or Command/CommandParameter.
I am using Telerik, HubSection is like Pivot with WP8.
<HubSection x:Uid="Section4Header" Header="All note" >
<DataTemplate>
<ListBox x:Name="listBoxobj" Background="Transparent" Margin="6" Height="auto" BorderThickness="2" MaxHeight="580" Grid.Row="1" SelectionChanged="listBoxobj_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="350" >
<Border Margin="5" BorderBrush="White" BorderThickness="1">
<Grid Holding="Grid_Holding" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="EditButton"
Text="Export To PDF"
Click="EditButton_Click"
/>
<MenuFlyoutItem x:Name="EditButton1"
Text="Export To PDF syncfu"
Click="EditButton1_Click"
/>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<TextBlock Margin="5,0,0,0" Grid.Row="0" x:Name="NameTxt" TextWrapping="Wrap" Text="{Binding Name}" FontSize="28" Foreground="White"/>
<TextBlock HorizontalAlignment="Right" Margin="0,0,35,0" Grid.Row="3" x:Name="CreateddateTxt" Foreground="White" FontSize="18" TextWrapping="Wrap" Text="{Binding CreationDate}" />
</Grid>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</HubSection>
C#
private void ReadWritePadFileContentList_Loaded(object sender, RoutedEventArgs e)
{
ReadAllWritePadFileContent dbnote = new ReadAllWritePadFileContent();
DB_ContactList = dbnote.GetAllContacts();//Get all DB contacts
if (DB_ContactList.Count > 0)
deleteAppBarButton.IsEnabled = true;
else
deleteAppBarButton.IsEnabled = false;
listBoxobj.ItemsSource = DB_ContactList.OrderByDescending(i => i.Id).ToList();//Binding DB data to LISTBOX and Latest contact ID can Display first.
}
listBoxobj is name of ListBox
the problem is So how can I acces the the listbox?
The name 'listBoxobj' does not exist in the current context
As Mike said, You wont be able to directly access the listbox from the hub's code, as its in a DataTemplate.
However, you can create a UserControl eg, MyUserControl1.
Put your ListBox inside the MyUserControl1.xaml file, and its related c# code in MyUserControl1.cs file.
Then, add the user control in your HubSection.
<HubSection x:Uid="Section4Header" Header="All note" >
<DataTemplate>
<local:MyUserControl1 x:Name="ListControl"/>
</DataTemplate>
</HubSection>
EDIT: Put your ListBox code inside the <Grid> your UserControl code:
<ListBox x:Name="listBoxobj" Background="Transparent" Margin="6" Height="auto" BorderThickness="2" MaxHeight="580" Grid.Row="1" SelectionChanged="listBoxobj_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="350" >
<Border Margin="5" BorderBrush="White" BorderThickness="1">
<Grid Holding="Grid_Holding" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="EditButton"
Text="Export To PDF"
Click="EditButton_Click"
/>
<MenuFlyoutItem x:Name="EditButton1"
Text="Export To PDF syncfu"
Click="EditButton1_Click"
/>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<TextBlock Margin="5,0,0,0" Grid.Row="0" x:Name="NameTxt" TextWrapping="Wrap" Text="{Binding Name}" FontSize="28" Foreground="White"/>
<TextBlock HorizontalAlignment="Right" Margin="0,0,35,0" Grid.Row="3" x:Name="CreateddateTxt" Foreground="White" FontSize="18" TextWrapping="Wrap" Text="{Binding CreationDate}" />
</Grid>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
You won't be able to do that directly as it's within a DataTemplate and your ListBox is therefore generated at runtime.
You might have some joy following the steps in this article to pull your ListBox out of the visual tree:
http://blogs.msdn.com/b/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx
!
I need to align the textblocks(PhoneTxt, CreateddateTxt ) which is present in listview.
<Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
<ListBox Background="Transparent" HorizontalAlignment="Left" Height="auto" BorderThickness="1" MaxHeight="580" Grid.Row="1" Margin="6" VerticalAlignment="Top" Width="352" Name="DaysLeftListView" SelectionChanged="DaysLeftListView_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="350" >
<Border Margin="5" BorderBrush="White" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Margin="5,0,0,0" Grid.Row="0" x:Name="NameTxt" TextWrapping="Wrap" Text="{Binding Events}" FontSize="28" Foreground="White"/>
<TextBlock Grid.Row="0" Text=">" FontSize="28" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Margin="5,0,0,0" Grid.Row="1" Name="PhoneTxt" TextWrapping="Wrap" Foreground="White" FontSize="18" Text="{Binding diff}" />
<TextBlock Margin="0,0,35,0" Grid.Row="2" Name="CreateddateTxt" Foreground="White" FontSize="18" TextWrapping="Wrap" Text="{Binding result}" />
</Grid>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
#Schuere There is an big gap between them..After appplying your code
I need to display .(i.e in output)Print them as together each other in a same row with some space..
# fillobotto I need to display those textblocks together with one or two spaces in between them
Try this
<ListBox Background="Transparent" HorizontalAlignment="Left" Height="auto" BorderThickness="1" MaxHeight="580" Grid.Row="1" Margin="6" VerticalAlignment="Top" Width="352" Name="DaysLeftListView" SelectionChanged="DaysLeftListView_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="350" >
<Border Margin="5" BorderBrush="White" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<TextBlock Margin="5,0,0,0" x:Name="NameTxt" TextWrapping="Wrap" Text="{Binding Events}" FontSize="28" Foreground="White"/>
<TextBlock Text=">" FontSize="28" Margin="5,0,0,0" Foreground="White"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Margin="5,0,0,0" Name="PhoneTxt" TextWrapping="Wrap" Foreground="White" FontSize="18" Text="{Binding diff}" />
<TextBlock Margin="5,0,0,0" Name="CreateddateTxt" Foreground="White" FontSize="18" TextWrapping="Wrap" Text="{Binding result}" />
</StackPanel>
</Grid>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Orientation="Horizontal" was missing
create some extra columndefinitions:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinitions Width="Auto"/>
<ColumnDefinitions Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Margin="5,0,0,0" Grid.Row="0" Grid.Column="0" ColumnSpan x:Name="NameTxt" TextWrapping="Wrap" Text="{Binding Events}" FontSize="28" Foreground="White"/>
<TextBlock Grid.Row="0" Grid.Column="1" Text=">" FontSize="28" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="White"/>
<TextBlock Margin="5,0,0,0" Grid.Row="1" Grid.Column="0" Name="PhoneTxt" TextWrapping="Wrap" Foreground="White" FontSize="18" Text="{Binding diff}" />
<TextBlock Margin="0,0,35,0" Grid.Row="1" Grid.Column="1" Name="CreateddateTxt" Foreground="White" FontSize="18" TextWrapping="Wrap" Text="{Binding result}" />
</Grid>
This should change the outcome, the CreateddateTxt should be right next to PhoneTxt
I don't understand perfectly which TextBlock you want to align, but you shoud use a StackPanel control and set its Orientation property to Horizontal.
<ListBox Background="Transparent" HorizontalAlignment="Left" Height="auto" BorderThickness="1" MaxHeight="580" Grid.Row="1" Margin="6" VerticalAlignment="Top" Width="352" Name="DaysLeftListView" SelectionChanged="DaysLeftListView_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Width="350" >
<Border Margin="5" BorderBrush="White" BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Margin="5,0,0,0" Grid.Row="0" x:Name="NameTxt" TextWrapping="Wrap" Text="{Binding Events}" FontSize="28" Foreground="White"/>
<TextBlock Grid.Row="0" Text=">" FontSize="28" HorizontalAlignment="Right" VerticalAlignment="Center" Foreground="White"/>
<StackPanel Grid.Row="1">
<TextBlock Margin="5,0,0,0" Name="PhoneTxt" TextWrapping="Wrap" Foreground="White" FontSize="18" Text="{Binding diff}" />
<TextBlock Margin="5,0,0,0" Name="CreateddateTxt" Foreground="White" FontSize="18" TextWrapping="Wrap" Text="{Binding result}" />
</StackPanel>
</Grid>
</Border>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
See the reference: https://msdn.microsoft.com/en-us/library/system.windows.controls.stackpanel.orientation%28v=vs.110%29.aspx
How to achieve this ui?
item1 | X
item2 | X
item3 | X
with item1,item2,item3 have SelectionChanged event and X is an image with tap event
I tried this
<telerikPrimitives:RadDataBoundListBox
x:Name="AddressListBox"
ItemsSource="{Binding hereRestAddressDetail}"
SelectedItem="{Binding hereRestDetail}"
SelectionChanged="AddressListBox_SelectionChanged"
ItemAnimationMode="PlayAll"
EmptyContent="">
<telerikPrimitives:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle Grid.Column="0" Grid.RowSpan="2" Width="10">
<Rectangle.Fill>
<SolidColorBrush Color="{StaticResource PhoneAccentColor}"/>
</Rectangle.Fill>
</Rectangle>
<StackPanel Grid.Column="1" Grid.RowSpan="2" >
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding LocalizedResources.by,
Source={StaticResource LocalizedStrings}}"
Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock Text="{Binding creator}" Margin="-8,0,0,0"
Style="{StaticResource PhoneTextAccentStyle}"/>
</StackPanel>
<TextBlock Text="{Binding street}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextLargeStyle}" />
<TextBlock Text="{Binding formatedStreet}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextSubtleStyle}" />
</StackPanel>
<Image Source="{Binding ratingButton}" Grid.Column="2"
Stretch="Uniform" Width="80"
Tag="{Binding Id}" Tap="rate_Tap"/>
<TextBlock Text="{Binding ratingValue}" HorizontalAlignment="Center"
TextWrapping="Wrap" Grid.Column="2" Grid.Row="1"
Style="{StaticResource PhoneTextSubtleStyle}"/>
</Grid>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>
but when I tap into image it will execute my event (in this condition I just testing it with showing messagebox ) but after that it also executing my SelectionChanged event...
how to specify that only image tap event that triggered when I tap into the image?
This should work:
bool ignoreSelectionChanged;
void rate_Tap(...) {
ignoreSelectionChanged = true;
//do you image tap things here
}
void AddressListBox_SelectionChanged(...) {
if(ignoreSelectionChanged) {
ignoreSelectionChanged = false; //reset the bool, so that it will skip only once
return;
}
//do your things on selection change here
}
I have a collection which shows in listbox. It's a listBoxItem of major listBox. Each listbox's item(not major) has a textbox and button. So, i need to get all collection when I tap on any button in listbox.
This is windows pnone 7 application. I want to get a list of items that are in listbBox.
I know how to get one item if it's not a collection(just item of major listBox)
private void Audio_Button_Click(object sender, RoutedEventArgs e)
{
string uri = null;
TextBox tb = null;
var grid = (Grid)((Button)sender).Parent;
foreach (var child in grid.Children)
{
if (child is TextBox && (string)((TextBox)child).Tag == "URL")
{
tb = (TextBox)child;
}
}
uri = tb.Text;
but i dont know how to get all the items. The problem is in that the "sender" has type button, not a listBoxItem. And anyway, if it had type listBoxItem - i'm not sure i understand how to make a list of items(
Or maybe i can use another control, with out scrolling? collection is not very big. But i think i'll have the same problem(
Update:
<local:NewsTemplateSelector.Audio>
<DataTemplate>
<Grid Name="AudioGrid" MaxHeight="2000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="75"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>
<Image Source="{Binding SourceImage}" Width="75"/>
<TextBlock Text="{Binding SourceName}" Foreground="Black" FontSize="25" Grid.Column="1" TextWrapping="Wrap" />
<TextBlock Text="{Binding Texts}" Foreground="Black" FontSize="25" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Height="auto" />
<Image Source="{Binding Photo[0].Big}" Margin="10" Grid.Column="1" Grid.Row="2"/>
<TextBlock Text="{Binding Audio[0].Title}" Foreground="Black" FontSize="25" Margin="96,10,10,10" Grid.Column="1" Grid.Row="3" />
<Button Background="Black" Content="Play" Grid.Column="1" HorizontalAlignment="Left" Margin="10,7,0,10" Grid.Row="3" d:LayoutOverrides="Height" Width="74" Tap="Audio_Button_Click" />
<Image Source="images\like.jpg" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="4" Width="30" Margin="0,1.5,34,-1.5" d:LayoutOverrides="VerticalMargin"/>
<TextBlock Text="{Binding Likes}" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="4" Foreground="Black" TextWrapping="Wrap" Width="30" Margin="0,0.5,0,-0.5"/>
<Line X1="0" Y1="27" X2="420" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" Grid.Column="1" />
<Line X1="0" Y1="27" X2="80" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" />
<TextBox Text="{Binding Audio[0].Url}" Tag="URL" Visibility="Collapsed" />
</Grid>
</DataTemplate>
</local:NewsTemplateSelector.Audio>
and
<local:NewsTemplateSelector.Audios>
<DataTemplate>
<Grid Name="AudiosGrid" MaxHeight="2000">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="75"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="75"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="28"/>
</Grid.RowDefinitions>
<Image Source="{Binding SourceImage}" Width="75"/>
<TextBlock Text="{Binding SourceName}" Foreground="Black" FontSize="25" Grid.Column="1" TextWrapping="Wrap" />
<TextBlock Text="{Binding Texts}" Foreground="Black" FontSize="25" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Height="auto" />
<Image Source="{Binding Photo[0].Big}" Margin="10" Grid.Column="1" Grid.Row="2"/>
<ListBox Name="audiosListbox" ItemsSource="{Binding Audio}" MaxHeight="500" Margin="10" Grid.Column="1" Grid.Row="3" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Title}" Grid.Column="1" Foreground="Black" FontSize="25" />
<Button Content="Play" Background="Black" Tap="Audios_Button_Click" />
<TextBox Text="{Binding Audio.Url}" Tag="URL" Visibility="Collapsed" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Image Source="images\like.jpg" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="4" Width="30" Margin="0,1.5,34,-1.5" d:LayoutOverrides="VerticalMargin"/>
<TextBlock Text="{Binding Likes}" Grid.Column="1" HorizontalAlignment="Right" Grid.Row="4" Foreground="Black" TextWrapping="Wrap" Width="30" Margin="0,0.5,0,-0.5"/>
<Line X1="0" Y1="27" X2="420" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" Grid.Column="1" />
<Line X1="0" Y1="27" X2="80" Y2="27" Margin="0,-28,0,0" Stroke="Gray" StrokeThickness="1" />
</Grid>
</DataTemplate>
</local:NewsTemplateSelector.Audios>
I have
You could use Linq To Visual Tree (download code, just one file) to get the Listbox that holds all the items. This code on the click handler should work for it.
var parentLb = ((Button)sender).Ancestors().FirstOrDefault(x => x is Listbox) as Listbox;
if(parentLb != null)
{
// Cast the ItemsSource property to the list type you're using...
var list = parentLb.ItemsSource
// And do whatever you want with that list.
}
You should of course cast list to its original type.