Grid.IsSharedSizeScope 等效于 Windows 8 [英] Grid.IsSharedSizeScope equivalent for Windows 8

查看:20
本文介绍了Grid.IsSharedSizeScope 等效于 Windows 8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 8/RT XAML 中,是否有任何一种简单的(非自定义编码)等效于 WPF Grid.IsSharedSizeScope?

Is there any kind of simple (non-custom-coded) equivalent to WPFs Grid.IsSharedSizeScope in Windows 8/RT XAML?

我将 ListViewItem 分为 3 个水平部分,这 3 列需要与所有绑定的 ListViewItem 对齐(每列到最宽的宽度).

I have ListViewItems 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.

推荐答案

因为是 wpf,所以我找到了 Metro 解决方案.我把整个代码贴在这里.:)

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>

以及背后的代码.只是为了尝试没有使用 MVVM

and the code behind . just to give a try did not use MVVM

这里是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;
    }

我绑定的类如下

class test
{
    public string Name1 { get; set; }
    public string Name2 { get; set; }
    public string Name3 { get; set; }
}

希望这会有所帮助.

好的,最后一个答案我没有编辑,因为这有点太长了,我想展示我正在研究的整个演示,以便它可以使您受益.

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.

这篇关于Grid.IsSharedSizeScope 等效于 Windows 8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆