Is there any kind of simple (non-custom-coded) equivalent to WPFs Grid.IsSharedSizeScope
in Windows 8/RT XAML?
I have ListViewItem
s that are divided into 3 horizontal sections and those 3 columns need to be aligned (to the widest width each) to all the bound ListViewItem
.
Since that was for wpf I found a Metro solution to the problem. Ill paste the entire code in here. :)
<Page.Resources>
<DataTemplate x:Key="DataTemplate1" >
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Gray">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Text="{Binding Name1}"/>
</StackPanel>
<StackPanel Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Text="{Binding Name2}"/>
</StackPanel>
<StackPanel Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<TextBlock Text="{Binding Name3}"/>
</StackPanel>
</Grid>
</DataTemplate>
</Page.Resources>
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ListView Name="MyList" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch" Background="Yellow" ItemTemplate="{StaticResource DataTemplate1}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate
<!-- Here is the panel that will contain the items -->
<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Background="Pink" VerticalAlignment="Stretch"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</Grid>
and the code behind . just to give a try did not use MVVM
Here's the cs
List<test> li = new List<test>();
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
for (int i = 0; i < 10; i++)
{
li.Add(new test()
{
Name1 = "Anobik1" + i.ToString(),
Name2 = "Anobik1" +i.ToString(),
Name3 = "Anobik1" +i.ToString()
});
}
MyList.ItemsSource = li;
}
and the class that I bind was as follows
class test
{
public string Name1 { get; set; }
public string Name2 { get; set; }
public string Name3 { get; set; }
}
Hope this will help.
Ok and last answer I did not edit since this was a bit too long and wanted to show the entire demo i was researching on so that it could benifit you.