GridView ItemTemplate Full Width - xaml

My question is: how can I stretch the DataTemplate to the full width of the screen. I've tried many solutions but they does not work.
I've tried HorizontalContentAlignment, setting GridView.ItemContainerStyle and etc. But nothing works. Can anybody explain me how can I do this?
Here is part of my code:
<Grid Style="{StaticResource GeneralAppBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Pivot x:Name="AccountInfoOptions" Grid.Row="1">
<PivotItem Header="История">
<GridView ItemsSource="{x:Bind CheckoutList}" Margin="5,0,5,0">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:UserCheckout">
<StackPanel Orientation="Horizontal" BorderBrush="Transparent" Background="White" Padding="5" Margin="0,5,0,0">
<StackPanel Grid.Column="0" Orientation="Vertical" VerticalAlignment="Center" Margin="0,0,10,0">
<TextBlock FontSize="14" Text="{x:Bind CheckoutDate}" Foreground="#979797" />
<TextBlock FontSize="14" Text="{x:Bind CheckoutTime}" Foreground="#979797" />
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind CheckoutSum}" FontSize="22" FontWeight="Bold" />
<Image Source="/Assets/TengeIcon.png" Width="20" Margin="5,0,0,0"/>
</StackPanel>
<TextBlock Text="{x:Bind CheckoutTitle}" TextAlignment="Center" />
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</GridView.ItemContainerStyle>
</GridView>
</PivotItem>
</Pivot>

The key to making it work, is changing the ItemsPanelTemplate. Define it as a page resource:
<Page.Resources>
<ItemsPanelTemplate x:Key="ItemsPanelTemplate">
<ItemsStackPanel />
</ItemsPanelTemplate>
</Page.Resources>
Now set it as the ItemsPanel for your GridView:
<GridView ItemsSource="{x:Bind CheckoutList}"
Margin="5,0,5,0"
ItemsPanel="{StaticResource ResourceKey=ItemsPanelTemplate}">
This will allow individual items to stretch across the full width. You will still need to replace the root StackPanel in your DataTemplate with a Grid as Nikita suggested:
<DataTemplate x:DataType="local:UserCheckout">
<Grid BorderBrush="Transparent" Background="White" Padding="5" Margin="0,5,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Vertical" VerticalAlignment="Center" Margin="0,0,10,0">
<TextBlock FontSize="14" Text="{x:Bind CheckoutDate}" Foreground="#979797" />
<TextBlock FontSize="14" Text="{x:Bind CheckoutTime}" Foreground="#979797" />
</StackPanel>
<StackPanel Grid.Column="1" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind CheckoutSum}" FontSize="22" FontWeight="Bold" />
<Image Source="/Assets/TengeIcon.png" Width="20" Margin="5,0,0,0"/>
</StackPanel>
<TextBlock Text="{x:Bind CheckoutTitle}" TextAlignment="Center" />
</StackPanel>
</Grid>
</DataTemplate>
You already have the Grid.Column property set correctly for the inner StackPanels. It seems you were attempting to use a Grid there before.

Related

Can't get VariableSizedWrapGrid to wrap

I'm having issues getting the VariableSizedWrapGrid to wrap horizontally. All I can seem to get are my elements stacked vertically in a single column. I'm not sure what I'm missing.
Ideally I would like to have 3 columns of input fields. The number of fields changes depending on the table selected so they need to just, you know, wrap.
<ScrollViewer
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<VariableSizedWrapGrid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Orientation="Horizontal">
<ItemsControl
ItemsSource="{x:Bind ViewModel.CurrentRow.Values}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="models:RowValue">
<Grid Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
Text="{x:Bind key.ColumnValidation.column_label}"
Margin="0"
Padding="0"
Grid.Column="0">
</TextBlock>
<TextBox
Grid.Column="1"
Visibility="{x:Bind vm:Converters.IsTextBoxField(key.ColumnValidation.data_type)}"
Text="{x:Bind value}">
</TextBox>
<RichTextBlock
Visibility="{x:Bind vm:Converters.IsHyperlinkField(key.ColumnValidation.data_type)}">
<Paragraph>
<Span>
<Hyperlink />
</Span>
</Paragraph>
</RichTextBlock>
<DatePicker
Visibility="{x:Bind vm:Converters.IsDateField(key.ColumnValidation.data_type)}">
</DatePicker>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</VariableSizedWrapGrid>
</ScrollViewer>
Turns out I didn't fully understand how ItemsControl works. Managed to get it working like so:
<ScrollViewer
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ItemsControl
Height="Auto"
Width="Auto"
ItemsSource="{x:Bind EditRow.Values}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid
Orientation="Horizontal"
MaximumRowsOrColumns="4"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
ItemWidth="200"
ItemHeight="75">
</VariableSizedWrapGrid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="models:RowValue">
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
Width="190"
Margin="5">
<TextBox
Header="{x:Bind key.ColumnValidation.column_label}"
Visibility="{x:Bind vm:Converters.IsTextBoxField(key.ColumnValidation.data_type)}"
Text="{x:Bind value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
</TextBox>
<TextBox
Header="{x:Bind key.ColumnValidation.column_label}"
Visibility="{x:Bind vm:Converters.IsHyperlinkField(key.ColumnValidation.data_type)}"
Text="{x:Bind value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
</TextBox>
<!-- todo: create converter for fusion date format -->
<Viewbox VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<DatePicker
Header="{x:Bind key.ColumnValidation.column_label}"
Visibility="{x:Bind vm:Converters.IsDateField(key.ColumnValidation.data_type)}">
</DatePicker>
</Viewbox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>

How to layout a stack of textblocks using stackpanels and grid?

I have a basic UI where there are 6 textblocks, 3 for the values and 3 for the related headers. What I had set out originally was positioning the textblocks using the grid and column positions. This looked fine except for the value textblocks were positioned too close to their header teckblocks.
So to try an alternative solution, in my below code I wrapped each set of textblocks in a stackpanel and supplied a margin for the header textblock. But when testing all six controls appear bunched up together in the top right corner of the screen.
Question:
Does anyone know how to position a set of textblocks, stacked and with a space between the first and second block in each set?
During debug I tried playing around with the margin size on each stackpanel which didn't do anything to fix the layout.
Xaml markup of the UI:
<Grid x:Name="LayoutRoot" Background="#FF236A93">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition />
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<!-- ContentPanel contains details text. Place additional content here -->
<Grid x:Name="ContentPanel"
Grid.Row="1"
Height="600"
Margin="5,0,5,0"
Visibility="Visible">
<Grid.RowDefinitions>
<RowDefinition Height="1.6*" />
<RowDefinition Height="1.6*" />
<RowDefinition Height="1.6*" />
<RowDefinition Height="2*" />
<RowDefinition Height="2*" />
<RowDefinition Height="1.3*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=".5*" />
<ColumnDefinition Width="5*" />
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Row="0"
Grid.Column="1"
Margin="0,0,5,0"
Width="270"
Height="72"
HorizontalAlignment="Right"
VerticalAlignment="Top"
FontSize="24"
Foreground="Gray"
Text="Hourly Tariff:" />
<TextBlock Grid.Row="0"
Grid.Column="1"
Width="270"
Height="72"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
FontSize="24"
Foreground="White"
Text="{Binding SelectedZone.TariffPH}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Row="1"
Grid.Column="1"
Width="270"
Height="72"
Margin="0,0,5,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
FontSize="24"
Foreground="Gray"
Text="Hours Open:" />
<TextBlock Grid.Row="1"
Grid.Column="1"
Width="270"
Height="72"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
FontSize="24"
Foreground="White"
Text="{Binding SelectedZone.HoursOpen}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Row="2"
Grid.Column="1"
Width="270"
Height="72"
Margin="0,0,5,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
FontSize="24"
Foreground="Gray"
Text="Days Open:" />
<TextBlock Grid.Row="2"
Grid.Column="1"
Width="270"
Height="72"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
FontSize="24"
Foreground="White"
Text="{Binding SelectedZone.DaysOpen}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Row="3"
Grid.Column="1"
Width="270"
Height="72"
Margin="0,0,5,0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
FontSize="24"
Foreground="Gray"
Text="Parking Restrictions:" />
<TextBlock Grid.Row="3"
Grid.Column="1"
Width="270"
Height="72"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
FontSize="24"
Foreground="White"
Text="{Binding SelectedZone.Restrictions}" />
</StackPanel>
</Grid>
</Grid>
Proposed layout of UI:
If it were me, I'd just turn all that noise into something more like this for easier maintenance/readability and less objects in the DOM;
<!-- ContentPanel contains details text. Place additional content here -->
<StackPanel x:Name="ContentPanel"
Grid.Row="1" Margin="5,0">
<StackPanel.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="24"/>
<Setter Property="Width" Value="270"/>
<Setter Property="Foreground" Value="Gray"/>
<Setter Property="Margin" Value="0,5"/>
</Style>
</StackPanel.Resources>
<TextBlock>
<Run Text="Hourly Tariff:"/>
<LineBreak/>
<Run Text="{Binding SelectedZone.TariffPH}" Foreground="White"/>
</TextBlock>
<TextBlock>
<Run Text="Hours Open:"/>
<LineBreak/>
<Run Text="{Binding SelectedZone.HoursOpen}" Foreground="White"/>
</TextBlock>
<TextBlock>
<Run Text="Days Open:"/>
<LineBreak/>
<Run Text="{Binding SelectedZone.DaysOpen}" Foreground="White"/>
</TextBlock>
<TextBlock>
<Run Text="Parking Restrictions:"/>
<LineBreak/>
<Run Text="{Binding SelectedZone.Restrictions}" Foreground="White"/>
</TextBlock>
</StackPanel>
ADDENDUM: Just noticed you had your StackPanel's Horizontal. For the Same effect just remove the <LineBreak/> lines and they'll be horizontal.

Get height of all child ListViews

So I have a ScrollView with a StackPanel. Inside the StackPanel I have three ListViews with different List<object>-sources.
What I want to achieve is to disable scrolling on the ListViews and only scroll all of them in the same ScrollView.
I get something that scrolls a little bit okey when i hardcode the height of the scrollview, but if I don't do that it only snaps back to start after I release the finger. How can I achieve to get the height?
Current XAML:
<Style x:Key="ListViewHeaderDisableScroll" TargetType="ListView">
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False" />
</Style>
<Page
x:Class="TestApp.SecondaryView.PatientDetailView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ViewModels="using:TestApp.ViewModel"
mc:Ignorable="d">
<Page.DataContext>
<ViewModels:PatientDetailViewModel />
</Page.DataContext>
<Grid Background="White">
<StackPanel Orientation="Vertical">
/* Menu-Grid*/
<ScrollViewer VerticalScrollMode="Enabled" VerticalScrollBarVisibility="Hidden" IsVerticalRailEnabled="True" Height="800">
<StackPanel Name="StackPanel_Lists">
<ListView Style="{StaticResource ListViewHeaderDisableScroll}" ItemsSource="{Binding DummyProblems}" Background="White">
<ListView.Header>
<StackPanel Style="{StaticResource ListViewHeaderStackPanel}">
<TextBlock Text="HEADER 1" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"/>
<SymbolIcon Symbol="Play" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,0,10"/>
</StackPanel>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate x:DataType="ViewModels:PatientDetailViewModel">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock FontSize="20" Grid.Row="0" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Note}"></TextBlock>
<TextBlock FontSize="15" Grid.Row="1" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Fo}"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Style="{StaticResource ListViewHeaderDisableScroll}" ItemsSource="{Binding DummyMeasures}" Background="White">
<ListView.Header>
<StackPanel Background="DarkGray" Orientation="Horizontal" FlowDirection="LeftToRight" Padding="8,8,8,8">
<TextBlock Text="HEADER 2" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"/>
<SymbolIcon Symbol="Play" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,0,10"/>
</StackPanel>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate x:DataType="ViewModels:PatientDetailViewModel">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontSize="20" Grid.Row="0" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Description}"></TextBlock>
<TextBlock FontSize="15" Grid.Row="1" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Note}"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Style="{StaticResource ListViewHeaderDisableScroll}" ItemsSource="{Binding DummyGoals}" Background="White">
<ListView.Header>
<StackPanel Background="DarkGray" Orientation="Horizontal" FlowDirection="LeftToRight" Padding="8,8,8,8">
<TextBlock Text="HEADER 3" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="10,0,0,0"/>
<SymbolIcon Symbol="Play" Foreground="White" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,0,10"/>
</StackPanel>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate x:DataType="ViewModels:PatientDetailViewModel">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock FontSize="20" Grid.Row="0" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Description}"></TextBlock>
<TextBlock FontSize="15" Grid.Row="1" Foreground="DimGray" Margin="5,5,5,5" Text="{Binding Fo}"></TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</ScrollViewer>
</StackPanel>
</Grid>
So I found this:
The StackPanel outside og everything did ruin everything. I changed it to Grid and made the ScrollView *. Now everything works

ListView first item missing when binding width

i have this xaml code:
<ListView Name="MyList" ItemsSource="{Binding MyItems}"
ScrollViewer.HorizontalScrollMode="Disabled" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ElementName=MyList, Path=ActualWidth}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" Grid.Column="0" Grid.ColumnSpan="2" >
<TextBlock Text="{Binding aaa}" />
<TextBlock Text="{Binding bbb}" />
<TextBlock Text="{Binding ccc}"
TextWrapping="WrapWholeWords" TextTrimming="WordEllipsis" Height="25" MaxHeight="25" Margin="0,0,10,0" />
</StackPanel>
<TextBlock Grid.Column="1" Style="{StaticResource ListTitle}" Text="{Binding restaDaPagare}"
HorizontalAlignment="Right" Margin="0,0,10,0" />
<Canvas Grid.Column="2" Height="50" Width="50" Background="{StaticResource GrayBrush}"></Canvas>
<Image Grid.Column="2" Source="/Images/img.png"
Height="50" Width="50" MinHeight="50" MinWidth="50"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
For some reasons, if i use this instruction (row 5):
<Grid Width="{Binding ElementName=MyList, Path=ActualWidth}">
the first item of MyList disappears.
If i use this code:
<Grid Width="400">
everything works well... except that I don't want to use a static Width.
Thanks for any help!
You can try to not set any width for your Grid (in your template) and add this to your ListView
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
This idea was "taken" from this question

Bind ListViewItem's height to the ListView from dataTemplate

I have a ListView in my Windows Store App, which selects a template through dataTemplateSelector. In the ItemTemplate of ListView, i have an image. I don't want to fix the height and width of the image, i want to allow it to adjust itself with the space available. So the image can be displayed bigger in big screen size.
Following is my ListView XAML:
<ListView Name="MyListView" ItemTemplateSelector="{StaticResource MyTemplateConverter}"
Height="{Binding ActualHeight, ElementName=scroll, Converter={StaticResource BottomMarginConverter}}" Width="{Binding ActualWidth, Converter={StaticResource GVWIdthConverter}, ElementName=scroll}"
Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Tapped="MyGridView_Tapped">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" VerticalAlignment="Stretch" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="Margin" Value="0,5,0,5" />
<Setter Property="Background" Value="LightCyan" />
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="3" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
I have set VerticalContentAlignment to Stretch, this stretches my ListViewItem to the size of ListView, but the problem is when the image inside the Item is bigger, it increases the size of ListViewItem larger than ListView. I have also tried setting the height of ListViewItem in the above code by adding
<Setter Property="Height" Value="{Binding ActualHeight, ElementName=MyGridView}" />
Following is the code of my ItemTemplate, which is being selected through ItemTemplateSelector,
<DataTemplate x:Key="PhotoTemplate">
<Grid x:Name="PhotoTemplateGrid" Width="400" Margin="2" Background="LightPink" >
<Grid.RowDefinitions>
<RowDefinition Height="90"/>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="5" HorizontalAlignment="Stretch" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding from.photoUrl}" Height="70" HorizontalAlignment="Center" VerticalAlignment="Center" Width="70" />
<StackPanel Orientation="Vertical" Margin="10,10,0,0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top">
<TextBlock Grid.Column="1" Text="{Binding from.Name}" Style="{StaticResource SubHeaderText}" VerticalAlignment="Top"
IsHitTestVisible="false" TextWrapping="NoWrap" Foreground="{StaticResource StalkerBlueThemeBrush}" />
<TextBlock Text="{Binding created_Time, Converter={StaticResource TextDateConverter}}" Margin="0,0,0,0" Style="{StaticResource BaselineTextStyle}" VerticalAlignment="Top"
IsHitTestVisible="false" TextWrapping="NoWrap" FontSize="12" />
</StackPanel>
</Grid>
<Grid Grid.Row="1" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Margin="5,0,5,0" TextAlignment="Center" MaxHeight="40" HorizontalAlignment="Stretch" Text="{Binding message}" Style="{StaticResource BaselineTextStyle}"
TextTrimming="WordEllipsis" IsHitTestVisible="false" TextWrapping="Wrap" VerticalAlignment="Center" />
<TextBlock Grid.Row="1" MaxHeight="20" Margin="5,0,5,0" TextAlignment="Center" Text="{Binding description}" Style="{StaticResource BaselineTextStyle}"
TextTrimming="WordEllipsis" IsHitTestVisible="false" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Stretch" />
<Image Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Uniform" Source="{Binding picture}" Margin="2" />
</Grid>
<Grid Grid.Row="2" Background="LightGray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="15" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Height="Auto" Background="White" >
<Polygon Points="15,0 0,15 30,15" Stroke="LightGray" Fill="LightGray" Margin="20,0,0,0" />
</Grid>
<Grid Grid.Row="1" HorizontalAlignment="Stretch">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5,0,0,0" Text="View all comments" Style="{StaticResource BaselineTextStyle}" Foreground="{StaticResource BlueThemeBrush}" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,5,0">
<Image Height="15" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="25" Source="ms-appx:///Assets/CtBlueSmall.png" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Text="{Binding CtCount}" Foreground="White" />
<Image Height="15" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0,0,0,0" Width="25" Source="ms-appx:///Assets/LeBlueSmall.png" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" TextWrapping="NoWrap" TextTrimming="WordEllipsis" Text="{Binding LeCount}" Foreground="White" />
</StackPanel>
</Grid>
</Grid>
</Grid>
</DataTemplate>
The Grid at Row Number 1 <Grid Grid.Row="1" >, contains the image which makes the height go larger than the ListView. I want to allow this Grid to stretch itself to the size of its parent. But not cross the size of its parent. in other word, i simply want to bind its height to its parent. Please help me out, i am stuck here.
have you tried to change the Row Definition applied for that image to 'Auto'?
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
I have managed to solve this in my own project by binding the Height of the Grid in the DataTemplate to the ActualHeight of the ListView. I does not seem to work if the binding is in the ListView.ItemContainerStyle style as a setter.
<DataTemplate>
<Grid Height="{Binding ActualHeight, ElementName=MyListView}">
...
</Grid>
</DataTemplate>