Grid not covering all the screen in UWP app - xaml

Why my grid is not covering all the screen and how can i fix it? On the designer looks like it should be covering all the width of the screen, but actually leaves a big space on the rigth.
<Grid Background="GreenYellow">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="200"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
This code is only a snip, but even with childs the space its there on different sizes.
Edit 1:
Acoording to Luis C. answer i get the same result big empty space to the left:
I found a strange workaround to achieve what i want:
<Grid Background="Yellow">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="200"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<TextBlock Text="This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite. This is a very large text that only is used to strech all the childrens to the infinite" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Button Content="Black" Background="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
<Button Grid.Row="1" Content="Black" Background="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Button Grid.Row="2" Content="Black" Background="Blue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
The result is:
Still its a very strange way to workaround the problem.
Full Code
As you see, im using a SplitView on a GridView that loads Pages(like the one with the mentioned problem) on a Frame inside the SplitViewContent. Other Pages with TextBlock as childrens cover the whole screen as i want. The code for the SplitView is:
<Page
x:Class="MyProject.ViewModels.HomePage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyProject.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<RelativePanel>
<Button Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="" FontSize="36" Click="HamburgerButton_Click" Background="LightGray"/>
<!--<Button Name="BackButton" FontFamily="Segoe MDL2 Assets" Content="" FontSize="36" Visibility="Visible" Background="LightGray"/>-->
<CommandBar Name="Bar" RelativePanel.AlignRightWithPanel="True" ClosedDisplayMode="Compact" RelativePanel.RightOf="HamburgerButton" Visibility="Visible" Background="LightGray" IsOpen="False" IsSticky="True" >
<CommandBar.Content>
<TextBlock Name="BarTitle" Text="Title" FontSize="24" Margin="24,8,0,12" HorizontalAlignment="Center" VerticalAlignment="Center" />
</CommandBar.Content>
</CommandBar>
</RelativePanel>
<SplitView Name="MySplitView"
Grid.Row="1"
DisplayMode="Overlay"
OpenPaneLength="200"
CompactPaneLength="56"
HorizontalAlignment="Left">
<SplitView.Pane>
<ListBox SelectionMode="Single"
Name="IconsListBox"
SelectionChanged="IconsListBox_SelectionChanged">
<ListBoxItem Name="SymbolsListBoxItem">
<StackPanel Orientation="Horizontal">
<Image Source="x" Width="36" Height="36" HorizontalAlignment="Center" VerticalAlignment="Center"> </Image>
<TextBlock x:Uid="Symbols" Text="[Symbols]" FontSize="24" Margin="20,0,0,0" />
</StackPanel>
</ListBoxItem>
</ListBox>
</SplitView.Pane>
<SplitView.Content >
<Frame Name="FrameHolder"></Frame>
</SplitView.Content>
</SplitView>
<Frame Name="HomePageFrame" >
<!-- Frame not used by now-->
</Frame>
</Grid>
The full code page snippet is(with more children) and the result the same, big blank empty space to the right:
<Page
x:Class="MyProject.ViewModels.SymbolsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyProject.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:data="using:MyProject.Models"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
<Style TargetType="ListView" x:Key="myListViewStyle">
<Setter Property="AllowDrop" Value="False" />
<Setter Property="CanReorderItems" Value="False" />
<Setter Property="Width" Value="36"/>
<Setter Property="Height" Value="140"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="Padding" Value="0,4,0,0"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="BorderBrush" Value="White" />
<Setter Property="BorderThickness" Value="1" />
</Style>
<Style TargetType="TextBlock" x:Key="SymbolViewer">
<Setter Property="FontFamily" Value="/Fonts/etc"/>
<Setter Property="FontSize" Value="30" />
<Setter Property="Padding" Value="8"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<LinearGradientBrush x:Key="GradBackground" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="LightGray" Offset="0"/>
<GradientStop Color="White" Offset=".5"/>
<GradientStop Color="LightGray" Offset="1"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="ItemGradBackground" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="White" Offset=".5"/>
<GradientStop Color="LightGray" Offset="1"/>
</LinearGradientBrush>
</Page.Resources>
<!-- Spinners -->
<StackPanel Background="AliceBlue" HorizontalAlignment="Stretch" Padding="0">
<StackPanel Background="{StaticResource GradBackground}" >
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" >
<ListView Name="Uno" ItemsSource="{x:Bind UnoItems}" Style="{StaticResource myListViewStyle}" BorderBrush="White"
BorderThickness="2" IsItemClickEnabled="True" ItemClick="Uno_ItemClick">
<ListView.ItemTemplate >
<DataTemplate x:DataType="data:Thingy">
<TextBlock Text="{x:Bind Symbol}" FontFamily="/Fonts/etc"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!-- Not user interactive-->
<TextBlock Text="0" Width="36" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center" ></TextBlock>
<!-- Spinner 2 -->
<ListView Name="Dos" ItemsSource="{x:Bind DosItems}" Style="{StaticResource myListViewStyle}"
IsItemClickEnabled="True" ItemClick="Dos_ItemClick">
<ListView.ItemTemplate >
<DataTemplate x:DataType="data:Thingy">
<TextBlock Text="{x:Bind Symbol}" ></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="Tres" ItemsSource="{x:Bind TresItems}" Style="{StaticResource myListViewStyle}">
<ListView.ItemTemplate >
<DataTemplate x:DataType="data:Thingy">
<TextBlock Text="{x:Bind Symbol}" ></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="Cuatro" ItemsSource="{x:Bind TresItems}" Style="{StaticResource myListViewStyle}">
<ListView.ItemTemplate >
<DataTemplate x:DataType="data:Thingy">
<TextBlock Text="{x:Bind Symbol}" ></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="Cinco" ItemsSource="{x:Bind DosItems}" Style="{StaticResource myListViewStyle}">
<ListView.ItemTemplate >
<DataTemplate x:DataType="data:Thingy">
<TextBlock Text="{x:Bind Symbol}" ></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="Seiss" ItemsSource="{x:Bind TresItems}" Style="{StaticResource myListViewStyle}">
<ListView.ItemTemplate >
<DataTemplate x:DataType="data:Thingy">
<TextBlock Text="{x:Bind Symbol}"></TextBlock>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</StackPanel>
</StackPanel>

You just need to remove the "RowDefinition" without height and change the "Auto" Rows to "*".
Something like this:
<Grid Background="GreenYellow">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="200"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Content="Black" Background="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Button Grid.Row="1" Content="Black" Background="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
<Button Grid.Row="2" Content="Black" Background="Blue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>

Related

The splitview items aren't properly stacking beneath hamburger button

I am working on Visual Studio 2015 and trying to make a hamburger style navigation... but the items of the pane of the splitview are automatically getting a margin, and are not properly stacking beneath the hamburger button [look at the attached image]. I want them to properly stack beneath the Hamburger button on the leftmost of the grid.
I want to use the listbox so that when user navigates to a different page, it remains selected/highlighted, so I can't remove that.
I have attached the MainPage.xaml code and the code of the style i have used. Hope you would help .. Thanks!
<Page
x:Class="MathAssistant.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MathAssistant"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Name="HBbutton" Click="HBbutton_Click" Grid.Column="0" Grid.Row="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" FontFamily="Segoe MDL2 Assets" Content="" FontSize="25" Background="BlueViolet"/>
<TextBlock Name="Heading" Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" HorizontalAlignment="Center" FontSize="36" Foreground="CornflowerBlue" />
<SplitView Grid.Row="1"
Grid.ColumnSpan="2"
Name="Menu"
DisplayMode="CompactOverlay"
OpenPaneLength="270"
CompactPaneLength="56">
<SplitView.Pane>
<ListBox SelectionMode="Single"
SelectionChanged="MenuListBox_SelectionChanged">
<ListBoxItem Name="MenuItemUnitConverter">
<StackPanel Orientation="Horizontal">
<Image Margin="0" Source="Assets/unitconverterlogo.png" Style="{StaticResource SplitviewLogoStyle}" />
<TextBlock FontSize="24" Margin="20,0,0,0">
<Run Text="Unit Converter"/>
</TextBlock>
</StackPanel>
</ListBoxItem>
<ListBoxItem Name="MenuItemCalculator" >
<StackPanel Orientation="Horizontal">
<Image Margin="0" Source="Assets/calculatorlogo.png" Style="{StaticResource SplitviewLogoStyle}"/>
<TextBlock FontSize="24" Margin="20,0,0,0">Calculator</TextBlock>
</StackPanel>
</ListBoxItem>
</ListBox>
</SplitView.Pane>
<SplitView.Content>
<Frame Name="MyFrame" Grid.Column="1" Grid.Row="1"></Frame>
</SplitView.Content>
</SplitView>
</Grid>
<Application.Resources>
<Style TargetType="Image" x:Key="SplitviewLogoStyle">
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="45" />
</Style>
ListBoxItem has a default padding (that's the opposite of a margin) of "12,11,12,13". Try setting the Padding of the ListBoxItems to 0 then it should be aligned to the left. To set it in the center you could do something like this:
<ListBoxItem Name="MenuItemUnitConverter" Padding="0">
<StackPanel Orientation="Horizontal">
<Image Margin="4" Source="Assets/unitconverterlogo.png" Style="{StaticResource SplitviewLogoStyle}" />
<TextBlock FontSize="24" Margin="20,0,0,0">
<Run Text="Unit Converter"/>
</TextBlock>
</StackPanel>
</ListBoxItem>
And modify the Style so that image's margin on left + width + image's margin on the right = SplitView.Width (4+48+4=56):
<Style TargetType="Image" x:Key="SplitviewLogoStyle">
<Setter Property="Height" Value="50" />
<Setter Property="Width" Value="48" />
</Style>

XAML Element responsive width on Orientation change

I am building a Windows 8.1 Universal app. On the orientation change for the phone, the outer "Grid" element doesn't change in width when the phone is switched to Landscape mode (and vice versa if the app is originally opened in landscape - doesn't change width when orientation=portrait). The Width is bound to the PivotItem Width and the PivotItem fills the entire screen on orientation change but the Grid does not.
<Page x:Name="page"
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:m="using:App1.Models"
xmlns:vm="using:App1.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
mc:Ignorable="d">
<Page.BottomAppBar>
<CommandBar Foreground="White" Background="{StaticResource CustomResource}">
<AppBarButton x:Name="BackButton" Label="Back" HorizontalAlignment="Center"
Click="BackButton_Click" Icon="Back" />
<AppBarButton x:Name="ForwardButton" Label="Forward" HorizontalAlignment="Center"
Click="ForwardButton_Click" Icon="Forward" />
<AppBarButton x:Name="HomeButton" Label="Home" HorizontalAlignment="Center"
Click="HomeButton_Click" Icon="Home" />
<AppBarButton x:Name="SettingsButton" Label="Settings" HorizontalAlignment="Center"
Click="SettingsButton_Click" Icon="Setting" />
</CommandBar>
</Page.BottomAppBar>
<Page.Resources>
<DataTemplate x:Key="myHeader">
<TextBlock Text="{Binding}" FontFamily="CustomFont" />
</DataTemplate>
<Style x:Key="PivotStyle" TargetType="Pivot">
<Setter Property="HeaderTemplate" Value="{StaticResource myHeader}"/>
</Style>
<!--<dict:NumberConverter x:Key="myNumberConverter" />-->
</Page.Resources>
<d:Page.DataContext>
<vm:DesignTimeDataSample />
</d:Page.DataContext>
<Grid>
<Pivot x:Name="MyPivot"
Style="{StaticResource PivotStyle}"
Background="{StaticResource CustomItem}"
SelectionChanged="MyPivot_SelectionChanged"
Foreground="Purple"
Grid.Row="1">
<PivotItem x:Name="Feed"
Header="news feed"
FontFamily="CustomFont">
<ScrollViewer Name="ScrollViewer">
<StackPanel x:Name="stackPanel">
<ListView ItemsSource="{Binding TileStories}" x:Name="cont" Margin="0,10,0,10" Background="{StaticResource CustomItem}" BorderBrush="{StaticResource CustomItem}" Foreground="{StaticResource CustomItem}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="MinHeight" Value="0" />
<Setter Property="Margin" Value="0,10,0,10" />
<Setter Property="Foreground" Value="{StaticResource CustomItem}" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Border CornerRadius="20" BorderThickness="0" Background="White" HorizontalAlignment="Stretch">
<StackPanel Height="160" Orientation="Horizontal">
<Grid HorizontalAlignment="Stretch" Width="{Binding ActualWidth, ElementName=Feed, Mode=OneWay}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Image Source="{Binding ImagePath}" Margin="20"/>
</Grid>
<Grid Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" Margin="0,0,0.333,53" Grid.RowSpan="2" HorizontalAlignment="Stretch">
<TextBlock VerticalAlignment="Center"
LineStackingStrategy="BlockLineHeight"
LineHeight="20" MaxHeight="80"
TextWrapping="WrapWholeWords"
Text="{Binding Headline}" FontSize="18"
FontFamily="CustomItem" />
</Grid>
<Grid Grid.Row="1" Margin="0,0.333,0.333,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<TextBlock VerticalAlignment="Center"
HorizontalAlignment="Left"
Margin="5" Text="{Binding Date}"
Foreground="#FFBDBDBD"
FontFamily="CustomItem" />
</Grid>
<Grid Grid.Column="1">
<AppBarButton
Style="{StaticResource CustomItem}"
VerticalAlignment="Center"
Margin="0,0,0,2"
HorizontalAlignment="Right"
Icon="Read"
CommandParameter="{Binding Url}"
Click="StoryButton_Click" FontFamily="Global User Interface"/>
</Grid>
</Grid>
</Grid>
</Grid>
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<Button Foreground="White" Content="Send Notification" Grid.Row="0" HorizontalAlignment="Stretch" Name="ToastButton" Click="ToastButton_Click" Margin="0,0,0,25.333"/>
</StackPanel>
</ScrollViewer>
</PivotItem>
<PivotItem x:Name="News" Header="news">
<WebView x:Name="MyWebView" NavigationCompleted="MyWebView_NavigationCompleted"/>
</PivotItem>
</Pivot>
</Grid>
</Page>

Windows phone 8.1 Textblock width to Fill

I want to create the layout as shown in the following image's first section.
But with the code attached, I can only get the layout output as show in the bottom section of the image attached.
<ListView Grid.Row="1"
ItemsSource="{Binding Items}"
Margin="0,20,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<TextBlock TextWrapping="NoWrap"
TextTrimming="WordEllipsis"
Grid.Column="0"
Text="{Binding Name}"
Style="{ThemeResource ListViewItemTextBlockStyle}" />
<Image Grid.Column="1"
Source="image.png"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You don't need the StackPanel in the DataTemplate - the Grid you have is enough for this.
Also, in order to get the items to stretch, define a simple ListView.ItemContainerStyle in your ListView:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
So, full code:
<ListView Grid.Row="1"
ItemsSource="{Binding Items}"
Margin="0,20,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="40" />
</Grid.ColumnDefinitions>
<TextBlock TextWrapping="NoWrap"
TextTrimming="WordEllipsis"
Grid.Column="0"
Text="{Binding Name}"
Style="{ThemeResource ListViewItemTextBlockStyle}" />
<Image Grid.Column="1"
Source="image.png"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
Try it
<ColumnDefinition Width="100" />
instead of Width="*"

UWP reference control outside of data template

I'm trying to create a listview that has column headers and the lists fields mimics the width of its corresponding header. No bindings fail but the textblocks width in the data template don't match up with their headers width. I'm guessing because the data template can't find the element. Any ideas to get this to work?
<Grid Grid.Column="1" Grid.Row="1" x:Name="listViewHeaders" Height="50" VerticalAlignment="Top" Margin="10,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--<controls:CustomGridSplitter/>-->
<TextBlock x:Name="nameHeader" Grid.Column="0" Text="Name" />
<TextBlock x:Name="typeHeader" Grid.Column="1" Text="Type" />
<TextBlock x:Name="colorHeader" Grid.Column="2" Text="Color" />
</Grid>
<ListView x:Name="ListView" Grid.Row="1" Grid.Column="1" Background="#FF494949" Margin="10,50,10,0" ItemsSource="{Binding CurrentCardList}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ActualWidth, ElementName=ListView}">
<!--<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>-->
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Column="0" Width="{Binding ActualWidth, ElementName=nameHeader}" Text="{Binding Name}" />
<TextBlock Grid.Column="1" Width="{Binding ActualWidth, ElementName=typeHeader}" Text="{Binding Type}" />
<TextBlock Grid.Column="2" Width="{Binding ActualWidth, ElementName=colorHeader}" Text="{Binding Color}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
The bindings work fine. But you're assuming that TextBlock elements in the header row will fill out the entire table cell, which they won't. They only fill as much space as much text they contain. In your case that's about 30px. You can find this information by using the Live Visual Tree feature of VS 2015.
You can solve the problem by wrapping the header TextBlock elements in another element that will fill out all available space, such as Border. Here's the solution:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="listViewHeaders" Height="50" VerticalAlignment="Top" Margin="10,0" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--<controls:CustomGridSplitter/>-->
<Border Background="Blue" HorizontalAlignment="Stretch" Grid.Column="0" x:Name="nameHeader">
<TextBlock Text="Name" />
</Border>
<Border Background="Red" x:Name="typeHeader" Grid.Column="1">
<TextBlock Text="Type" HorizontalAlignment="Stretch" />
</Border>
<Border Background="Yellow" x:Name="colorHeader" Grid.Column="2">
<TextBlock Text="Color" HorizontalAlignment="Stretch" />
</Border>
</Grid>
<ListView x:Name="ListView" Background="#FF494949" Margin="10,50,10,0" ItemsSource="{Binding CurrentCardList}">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Width="{Binding ActualWidth, ElementName=ListView}">
<!--<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>-->
<StackPanel Orientation="Horizontal">
<TextBlock Grid.Column="0" Width="{Binding ActualWidth, ElementName=nameHeader}" Text="{Binding Name}" />
<TextBlock Grid.Column="1" Width="{Binding ActualWidth, ElementName=typeHeader}" Text="{Binding Type}" />
<TextBlock Grid.Column="2" Width="{Binding ActualWidth, ElementName=colorHeader}" Text="{Binding Color}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
</Grid>
This will create the following effect, which I believe is what you're after.
Here's the link to the complete solution - http://1drv.ms/1eUzLHl

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>