Viewbox fill all column grid space WPF - c#

I am creating a program to tell the user his account balance and stuff like that. I show this information on a Grid with a ViewBox (so it can be resized to any screen resolution) the problem is that the ViewBox does not fills its space at the Grid. Here is my code:
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Viewbox Grid.Row="0" Grid.Column="1" Stretch="Uniform" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<TextBlock Foreground="#5a5a5a" TextAlignment="Center" Margin="1">Subtotal</TextBlock>
</Viewbox>
<Viewbox Grid.Row="0" Grid.Column="2" Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBox Margin="5" Text="155.60" TextAlignment="Center" IsReadOnly="True"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="1" Stretch="Uniform" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<TextBlock Foreground="#5a5a5a" TextAlignment="Center" Margin="1">Descuentos</TextBlock>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="2" Stretch="Uniform" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBox Margin="5" Text="0.0" TextAlignment="Center"/>
</Viewbox>
</Grid>
Here is the result:
As you can see the "discount" TextBox is smaller than the above, and i need them to have the same width and height. How can i achieve this? I am putting everything inside a ViewBox to make the resize for me, but is it right? i already tried several methos like this one, but it makes the text really small.

You don't need the Viewboxes at all:
<TextBlock Grid.Row="0" Grid.Column="1" Foreground="#5a5a5a" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" TextAlignment="Center" Margin="1">Subtotal</TextBlock>
<TextBox Grid.Row="0" Grid.Column="2" Margin="5" Text="155.60" TextAlignment="Center" IsReadOnly="True"/>
<TextBlock Grid.Row="1" Grid.Column="1" Foreground="#5a5a5a" TextAlignment="Center" Margin="1">Descuentos</TextBlock>
<TextBox Grid.Row="1" Grid.Column="2" Margin="5" Text="0.0" TextAlignment="Center"/>
Works just fine on my machine, no matter how I resize it.
If you need to keep the Viewboxes you can force your Textboxes to be the same size using Bindings
<Viewbox Grid.Row="0" Grid.Column="1" Stretch="Uniform" >
<TextBlock Foreground="#5a5a5a" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" TextAlignment="Center" Margin="1">Subtotal</TextBlock>
</Viewbox>
<Viewbox Grid.Row="0" Grid.Column="2" Stretch="Uniform" >
<TextBox x:Name="SubtotalBox" Grid.Row="0" Grid.Column="2" Margin="5" Text="155.60" TextAlignment="Center" IsReadOnly="True"/>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="1" Stretch="Uniform" >
<TextBlock Grid.Row="1" Grid.Column="1" Foreground="#5a5a5a" TextAlignment="Center" Margin="1">Descuentos</TextBlock>
</Viewbox>
<Viewbox Grid.Row="1" Grid.Column="2" Stretch="Uniform" >
<TextBox Grid.Row="1" Grid.Column="2" Margin="5" Text="0.0" MaxLength="6" Height="{Binding ElementName=SubtotalBox, Path=ActualHeight}" Width="{Binding ElementName=SubtotalBox, Path=ActualWidth}" TextAlignment="Center"/>
</Viewbox>
This binds the Width and Height of the second Textbox to the same as the first, keeping it consistent and forcing the Viewbox to size up to accommodate the bigger TextBox.

Related

Trouble with WPF ScrollViewer resize

I have an issue with a ScrollViewer in WPF.
When a Window is sized down to the point where the ScrollViewer should start taking over, the window doesn't resize the containing grid and bottom of the scroll bar just goes out of view.
I have tried binding the height of it to the height of the containing grid, but with no luck.
Here is my xaml:
<Grid x:Name="MainGrid" Width="Auto" Height ="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<StackPanel Height="134" Width="Auto" VerticalAlignment="Top" Background="Blue" HorizontalAlignment="Stretch">
<Label x:Name="ProjectNumberLabel" Content="ProjectNumber" HorizontalAlignment="Left" Height="45.5" VerticalAlignment="Top" Width="350" FontSize="32" Margin="10,0,0,0" Foreground="White"/>
<Label x:Name="ProjectNameLabel" Content="ProjectName" HorizontalAlignment="Stretch" Height="42" VerticalAlignment="Top" FontSize="24" Margin="10,0,0,0" Foreground="White" Width="auto"/>
<Label x:Name="SetLabel" Content="Set Id" HorizontalAlignment="Stretch" Width="Auto" Height="42" Margin="10,0,10,0" FontSize="24" VerticalAlignment="Top" Foreground="White" />
</StackPanel>
<ScrollViewer HorizontalAlignment="Stretch" Margin="0,140,0,0" Width="Auto" CanContentScroll="True" Height="{Binding ElementName=MainGrid, Path=ActualHeight }">
<StackPanel Name="ContainingPanel" VerticalAlignment="Top" HorizontalAlignment="Stretch" Width="Auto" Height="Auto">
<StackPanel HorizontalAlignment="Stretch" Width="Auto" Height="300"/>
<StackPanel HorizontalAlignment="Stretch" Height="38" VerticalAlignment="Bottom">
<CheckBox x:Name="ComplexDataCheckBox" Content="Show All Data" Click="ComplexDataCheckBox_Click" RenderTransformOrigin="1.751,0.547" Margin="0,4,0,0" Height="16" HorizontalAlignment="Right" Width="105" VerticalAlignment="Bottom">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</CheckBox.LayoutTransform>
</CheckBox>
</StackPanel>
<StackPanel HorizontalAlignment="Stretch">
<syncfusion:SfDataGrid HorizontalAlignment="Stretch" Width="Auto" VerticalAlignment="Stretch" x:Name="SpecimenGrid" AutoGenerateColumns="True" RowStyleSelector="{StaticResource styleselector}"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Grid>
if ScrollViewer has a Height equal to Grid height and not zero-vertical margin, it goes out Grid bounds.
it is better to put StackPanel and ScrollViewer in two separate Grid Rows:
<Grid x:Name="MainGrid">
<Grid.RowDefinitions>
<RowDefinition Height="140"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<!--Content-->
</StackPanel>
<ScrollViewer Grid.Row="1"
HorizontalAlignment="Stretch"
Margin="0"
CanContentScroll="True" >
<!--Content-->
</ScrollViewer>
</Grid>

UWP SplitView Issue After Installing Visual Studio 2015.1

After installing update 1 for Visual Studio 2015, SplitView control for UWP broken on Windows 10. As you know, SplitView have 2 sub items, an object grid and pane.
Now, an XAML error says that, "You cannot insert a object into SplitView".
I'm trying move object grid outside of SplitView. It is running at this case. However, the grid could not fitting the UI.
In addition to this, when I try adding new SplitView control to the page, it thrown a NullReferenceException.
I have not any issues like that on VS 2015 RTM. Are anyone encountered with this issue ?
Thanks...
My XAML Code is here:
<SplitView x:Name="MenuViewer" Margin="0" OpenPaneLength="200" PaneBackground="{StaticResource BorderColor}" RequestedTheme="Light" DisplayMode="CompactOverlay" FontSize="16" PaneClosing="MenuViewer_PaneClosing">
<SplitView.Pane>
<Grid x:Name="PanelGrid" ManipulationCompleted="PanelGrid_ManipulationCompleted" ManipulationMode="TranslateX">
<Grid.RowDefinitions>
<RowDefinition Height="48"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid x:Name="MenuButtonGrid" Margin="0" Background="{StaticResource Dark Main Color}" RequestedTheme="Light">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="" Background="Transparent" Click="HamburgerButton_Click" VerticalAlignment="Center" Foreground="White" HorizontalAlignment="Center" RequestedTheme="Light" FontSize="16" Width="48" Height="48"/>
<TextBlock x:Name="MenuText" Grid.Column="1" Margin="10,12" TextWrapping="Wrap" Text="Menu" Foreground="White" RequestedTheme="Light" FontSize="16"/>
</Grid>
<Grid x:Name="MenuStack" Margin="0,10,0,0" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.Transitions>
<TransitionCollection>
<EdgeUIThemeTransition Edge="Bottom"/>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.Transitions>
<StackPanel x:Name="UserDetailPanel" Orientation="Vertical">
<Image x:Name="UserImage" Source="ms-appx:///Images/ProfileHolder.png" Width="100" Height="100" Margin="0"/>
<TextBlock x:Name="UserName" TextWrapping="Wrap" Text="" FontSize="16" Margin="10,0" TextAlignment="Center"/>
<Border x:Name="LogoutBorder" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="0,0,0,1" Margin="0,10,0,0" PointerEntered="LogoutBorder_PointerEntered" PointerExited="LogoutBorder_PointerExited" PointerPressed="LogoutBorder_PointerPressed" BorderBrush="{StaticResource TextColor}" >
<TextBlock x:Name="LogoutText" TextWrapping="Wrap" Text="Logout" Foreground="#FF777777" TextAlignment="Center"/>
</Border>
</StackPanel>
<ListView x:Name="MenuList" ItemsSource="{Binding Menu}" ItemTemplate="{StaticResource ListView_TripItemTemplate}" FontSize="16" SelectionChanged="MenuList_SelectionChanged" Margin="-10,10,0,0" Grid.Row="1" VerticalAlignment="Top" />
<ListView x:Name="MenuList_2" ItemsSource="{Binding Second_menu}" ItemTemplate="{StaticResource ListView_TripItemTemplate}" FontSize="16" VerticalAlignment="Bottom" SelectionMode="None" Margin="-10,0,0,48" Grid.Row="2" />
</Grid>
</Grid>
</SplitView.Pane>
<Grid x:Name="Main" Background="{StaticResource Background}" ManipulationMode="TranslateX" ManipulationCompleted="Main_ManipulationCompleted">
<Grid.RowDefinitions>
<RowDefinition Height="48"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid x:Name="Header" Margin="0" Background="{StaticResource Dark Main Color}">
<Grid.Transitions>
<TransitionCollection/>
</Grid.Transitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="64"/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition Width="64"/>
</Grid.ColumnDefinitions>
<Button x:Name="HamburgerButton2" FontFamily="Segoe MDL2 Assets" Content="" Background="Transparent" Click="HamburgerButton_Click" VerticalAlignment="Center" Margin="0" HorizontalAlignment="Center" Foreground="White" FontSize="16" RequestedTheme="Light" Visibility="Collapsed"/>
<Button x:Name="AddButton" FontFamily="Segoe MDL2 Assets" Content="" Background="Transparent" Click="AddButton_Click" VerticalAlignment="Center" Margin="0" HorizontalAlignment="Center" Foreground="White" FontSize="16" Grid.Column="3" RequestedTheme="Light" Width="64" Height="48"/>
<AutoSuggestBox x:Name="SearchBar" Grid.Column="2" VerticalAlignment="Center" Margin="10,0" PlaceholderText="Search" FontSize="16" Style="{StaticResource AutoSuggestBoxStyle_TripLog}" BorderThickness="0" QuerySubmitted="SearchBar_QuerySubmitted" Background="#B2E9E9E9">
<AutoSuggestBox.QueryIcon>
<SymbolIcon Symbol="Find"/>
</AutoSuggestBox.QueryIcon>
</AutoSuggestBox>
<Button x:Name="Search_Button" FontFamily="Segoe MDL2 Assets" Content="" Background="Transparent" Click="Search_Button_Click" VerticalAlignment="Center" Margin="0" HorizontalAlignment="Right" Foreground="White" FontSize="16" Grid.Column="2" RequestedTheme="Light" Width="64" Height="48" Visibility="Collapsed"/>
<TextBlock x:Name="Operation_Header" Margin="10,12" TextWrapping="Wrap" Text="Test" FontSize="16" Foreground="White" RequestedTheme="Light" Grid.ColumnSpan="2"/>
</Grid>
<Grid x:Name="MobileSearch_Grid" Grid.Row="1" Visibility="Collapsed">
<Grid.RowDefinitions>
<RowDefinition Height="48"/>
<RowDefinition/>
</Grid.RowDefinitions>
<AutoSuggestBox x:Name="SearchBar_Mobile" VerticalAlignment="Stretch" Margin="10,5" PlaceholderText="" FontSize="16" Style="{StaticResource AutoSuggestBoxStyle_TripLog}" BorderThickness="0,0,0,13" QuerySubmitted="SearchBar_QuerySubmitted" Background="#B2E9E9E9"/>
</Grid>
</Grid>
</SplitView>
Answer which comes from Microsoft Connect solves my issue. Thanks for contiributions.
Hi.
We have worked with the Windows SDK team to get this fixed in a future
version of the Windows Software Development Kit. We have a workaround
that should fix the issue for you. Please "repair" the install, by
opening "Add or remove programs," and repairing the "Windows Software
Development Kit" matching the version 10.0.10586.15.
Thank you!
Jeremiah

3 column grid for xaml is not taking up expected space

I have the following xaml:
<DataTemplate x:Key="ActivityStreamItemTemplate">
<StackPanel VerticalAlignment="Top" Margin="5,0,0,0">
<Button Command="{Binding Path=DataContext.LoadSpacesCommand, ElementName=OrganisationList}" CommandParameter="{Binding}" Padding="-5,0,-5,-5" Margin="-7,-12,-7,-7" Height="auto" BorderThickness="0" HorizontalAlignment="Left" VerticalAlignment="Stretch" HorizontalContentAlignment="Left" UseLayoutRounding="True" FontSize="0.01">
<Grid Height="auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="67" />
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="67" />
</Grid.ColumnDefinitions>
<StackPanel Height="auto" Grid.Column="0" Background="Transparent">
<Border Background="Transparent" BorderThickness="0" Width="62" Height="62" HorizontalAlignment="Left" Margin="0,0,0,5">
<Image Source="{Binding created_by.image.link}" Width="62" Height="62"></Image>
</Border>
</StackPanel>
<StackPanel Height="auto" Grid.Column="1">
<TextBlock Text="{Binding type}" HorizontalAlignment="Left" FontSize="30" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" />
<TextBlock Text="{Binding ttitle}" HorizontalAlignment="Left" FontSize="15" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" TextWrapping="Wrap" MaxWidth="Infinity" />
<TextBlock Text="{Binding created_by.name}" HorizontalAlignment="Left" FontSize="11" VerticalAlignment="Center" Margin="0,0,0,5" Foreground="White" />
</StackPanel>
<StackPanel Height="auto" Grid.Column="2">
<TextBlock Text="{Binding comment_count}"></TextBlock>
</StackPanel>
</Grid>
</Button>
</StackPanel>
</DataTemplate>
As you can see I would like to have the first column of my grid set to 67.. perfect, and working fine...
The next column needs to fill as much as it can of the screen minus the extra columns width after it.
How do I go about doing this?
Kind of linked to this: How to TextWrap a TextBlock within a width Auto Column? but I couldn't get the * thing to work... I'm not sure it really does what I need it to do
It's because you've got:
MaxWidth="Infinity"
on your TextBlock and
<ColumnDefinition Width="Auto"/>
on your column.
This means that the XAML thinks it can grow that column as much as it likes to fit the text in.
If you want the text to wrap you'll have to provide a limit to either the width of the column, the width of the grid or the width of the stack panel.
If you want the middle column to take the remaining space then just specify it's width with a *:
<ColumnDefinition Width="*"/>

LongListSelector focus on item

I have this LongListSelector in my app page:
<Controls:LongListSelector x:Name="searchList" Margin="0,0,0,0" Background="White" SelectionChanged="DidPressSelectSearchList" HorizontalContentAlignment="Stretch" Grid.Row="1">
<Controls:LongListSelector.ItemTemplate>
<DataTemplate>
<local:SearchTemplateSelector Content="{Binding}" HorizontalContentAlignment="Stretch">
<local:SearchTemplateSelector.GoogleSuggestTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Rectangle Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Fill="Black" Opacity="0.3"/>
<TextBlock Text="{Binding}" FontSize="25" Foreground="Black" TextWrapping="Wrap" Grid.Row="1" Margin="0,10"/>
</Grid>
</DataTemplate>
</local:SearchTemplateSelector.GoogleSuggestTemplate>
<local:SearchTemplateSelector.VideoTemplate>
<DataTemplate>
<Grid>
<Rectangle Height="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" Fill="Black" Opacity="0.3" />
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Margin="0" Source="{Binding Path=ImgUrl}" HorizontalAlignment="Left" Width="100" Height="100" Tag="{Binding idStr}"/>
<Grid Grid.Column="1" Margin="10,0,8,0">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding Name}" FontSize="20" Foreground="Black" TextWrapping="Wrap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<StackPanel Orientation="Horizontal" Margin="0,-5,0,0" Grid.Row="1">
<TextBlock Text="Views: " FontSize="20" Foreground="Black"/>
<TextBlock Text="{Binding ViewCount}" FontSize="20" Foreground="Black"/>
</StackPanel>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding TimeStr}" FontSize="20" Foreground="Black" Margin="0,0,0,0" />
<TextBlock Text="Cached" FontSize="20" Foreground="Red" Margin="20,0,0,0" Grid.Column="1" />
</Grid>
</Grid>
</Grid>
</Grid>
</DataTemplate>
</local:SearchTemplateSelector.VideoTemplate>
</local:SearchTemplateSelector>
</DataTemplate>
</Controls:LongListSelector.ItemTemplate>
</Controls:LongListSelector>
And i noticed that when i press a item in the list so the user not have any thing to know which item he pressed, something like focus the item when he press it.
In iPhone the the selected row get blue and when release the blue selection is disappear,there is some equivalent to this in windows phone too?
Use TiltEffect from Silverlight Toolkit for Windows Phone, details are here http://www.geekchamp.com/articles/silverlight-for-wp7-toolkit-tilteffect-in-depth. Also to make an effect more expressive use Button as a container for your ItemTemplate with EmptyButtonStyle http://www.jeff.wilcox.name/2011/10/hyperlinkbutton-empty-style-for-phone/.

How to get the full collection of listbox, when i tap on the button, which is in listbox's item?

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.

Categories