Windows 8 XAML中多列文本中的分栏符

Windows 8 XAML中多列文本中的分栏符,xaml,windows-8,multiple-columns,Xaml,Windows 8,Multiple Columns,描述了如何在Windows 8 Metro样式应用程序中创建带水平滚动的多列文本。是否有办法添加“列中断”来获得标题顶部的标题,而不是在中间(记住,我们不知道每个栏有多少列): 您可以创建ItemsControl并将RichTextColumns作为数据模板。每列都位于绑定到ItemsControl的列表中 以下是XAML示例: <ItemsControl x:Name="itemsControl"> <ItemsControl.ItemsPanel>

描述了如何在Windows 8 Metro样式应用程序中创建带水平滚动的多列文本。是否有办法添加“列中断”来获得标题顶部的标题,而不是在中间(记住,我们不知道每个栏有多少列):


您可以创建ItemsControl并将RichTextColumns作为数据模板。每列都位于绑定到ItemsControl的列表中

以下是XAML示例:

<ItemsControl x:Name="itemsControl">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <!-- Content is allowed to flow across as many columns as needed -->
            <common:RichTextColumns x:Name="richTextColumns" Margin="25,20,25,20">
                <RichTextBlock x:Name="richTextBlock" Width="200" Style="{StaticResource ItemRichTextStyle}" IsTextSelectionEnabled="False">
                    <Paragraph>
                        <Run FontSize="26.667" FontWeight="Light" Text="{Binding Title}"/>
                        <LineBreak/>
                        <LineBreak/>                                
                    </Paragraph>                            
                    <Paragraph>
                        <Run FontWeight="SemiLight" Text="{Binding Content}"/>
                    </Paragraph>
                </RichTextBlock>

                <!-- Additional columns are created from this template -->
                <common:RichTextColumns.ColumnTemplate>
                    <DataTemplate>
                        <RichTextBlockOverflow Width="200" Margin="80,0,0,0">
                            <RichTextBlockOverflow.RenderTransform>
                                <TranslateTransform X="-1" Y="4"/>
                            </RichTextBlockOverflow.RenderTransform>
                        </RichTextBlockOverflow>
                    </DataTemplate>
                </common:RichTextColumns.ColumnTemplate>
            </common:RichTextColumns>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

以下是C#代码隐藏示例:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    var samples = new List<SampleColumnData>
    {
        new SampleColumnData{
            Title = "Column1",
            Content = "Just the good ol' boys, never meanin' no harm. Beats all you've ever saw, been in trouble with the law since the day they was born. Straight'nin' the curve, flat'nin' the hills. Someday the mountain might get 'em, but the law never will. Makin' their way, the only way they know how, that's just a little bit more than the law will allow. Just good ol' boys, wouldn't change if they could, fightin' the system like a true modern day Robin Hood. Knight Rider, a shadowy flight into the dangerous world of a man who does not exist. Michael Knight, a young loner on a crusade to champion the cause of the innocent, the helpless in a world of criminals who operate above the law. I never spend much time in school but I taught ladies plenty. It's true I hire my body out for pay, hey hey. I've gotten burned over Cheryl Tiegs, blown up for Raquel Welch. But when I end up in the hay it's only hay, hey hey. I might jump an open drawbridge, or Tarzan from a vine. 'Cause I'm the unknown stuntman that makes Eastwood look so fine. Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. Birds taught me to sing, when they took me to their king, first I had to fly, in the sky so high so high, so high so high so high, so - if you want to sing this way, think of what you'd like to say, add a tune and you will see, just how easy it can be. Treacle pudding, fish and chips, fizzy drinks and liquorice, flowers, rivers, sand and sea, snowflakes and the stars are free. La la la la la, la la la la la la la, la la la la la la la, la la la la la la la la la la la la la, so - Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. "
        },
        new SampleColumnData{
            Title = "Column2",
            Content = "Just the good ol' boys, never meanin' no harm. Beats all you've ever saw, been in trouble with the law since the day they was born. Straight'nin' the curve, flat'nin' the hills. Someday the mountain might get 'em, but the law never will. Makin' their way, the only way they know how, that's just a little bit more than the law will allow. Just good ol' boys, wouldn't change if they could, fightin' the system like a true modern day Robin Hood. Knight Rider, a shadowy flight into the dangerous world of a man who does not exist. Michael Knight, a young loner on a crusade to champion the cause of the innocent, the helpless in a world of criminals who operate above the law. I never spend much time in school but I taught ladies plenty. It's true I hire my body out for pay, hey hey. I've gotten burned over Cheryl Tiegs, blown up for Raquel Welch. But when I end up in the hay it's only hay, hey hey. I might jump an open drawbridge, or Tarzan from a vine. 'Cause I'm the unknown stuntman that makes Eastwood look so fine. Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. Birds taught me to sing, when they took me to their king, first I had to fly, in the sky so high so high, so high so high so high, so - if you want to sing this way, think of what you'd like to say, add a tune and you will see, just how easy it can be. Treacle pudding, fish and chips, fizzy drinks and liquorice, flowers, rivers, sand and sea, snowflakes and the stars are free. La la la la la, la la la la la la la, la la la la la la la, la la la la la la la la la la la la la, so - Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. "
        },
        new SampleColumnData{
            Title = "Column3",
            Content = "Just the good ol' boys, never meanin' no harm. Beats all you've ever saw, been in trouble with the law since the day they was born. Straight'nin' the curve, flat'nin' the hills. Someday the mountain might get 'em, but the law never will. Makin' their way, the only way they know how, that's just a little bit more than the law will allow. Just good ol' boys, wouldn't change if they could, fightin' the system like a true modern day Robin Hood. Knight Rider, a shadowy flight into the dangerous world of a man who does not exist. Michael Knight, a young loner on a crusade to champion the cause of the innocent, the helpless in a world of criminals who operate above the law. I never spend much time in school but I taught ladies plenty. It's true I hire my body out for pay, hey hey. I've gotten burned over Cheryl Tiegs, blown up for Raquel Welch. But when I end up in the hay it's only hay, hey hey. I might jump an open drawbridge, or Tarzan from a vine. 'Cause I'm the unknown stuntman that makes Eastwood look so fine. Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. Birds taught me to sing, when they took me to their king, first I had to fly, in the sky so high so high, so high so high so high, so - if you want to sing this way, think of what you'd like to say, add a tune and you will see, just how easy it can be. Treacle pudding, fish and chips, fizzy drinks and liquorice, flowers, rivers, sand and sea, snowflakes and the stars are free. La la la la la, la la la la la la la, la la la la la la la, la la la la la la la la la la la la la, so - Barnaby The Bear's my name, never call me Jack or James, I will sing my way to fame, Barnaby the Bear's my name. "
        },
    };

    itemsControl.ItemsSource = samples;
}
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
var样本=新列表
{
新样本列数据{
Title=“Column1”,
内容="只是好孩子,从来没有伤害过他们。你所见过的一切都被打败了,从他们出生的那一天起就被法律所困扰。在曲线上笔直,在山丘上平坦。总有一天山可能会得到他们,但法律永远不会。让他们走,这是他们知道的唯一方式,这只是比法律允许的多一点而已。很好老伙计们,如果可以的话,他们不会改变,像一个真正的现代罗宾汉一样与这个体系作战。骑士,一个进入一个不存在的人的危险世界的阴影飞行。迈克尔·奈特,一个年轻的独行侠,在一个罪犯凌驾于法律之上的世界里,为无辜者和无助者的事业进行十字军东征。我从不花太多时间我在学校教过很多女士。我确实是为了报酬才把我的身体租出去的,嘿嘿。我因为谢丽尔·蒂格斯被烧伤了,因为拉奎尔·韦尔奇被炸了。但是当我最后在干草里的时候,那只是干草,嘿嘿。我可能会跳一座敞开的吊桥,或者从藤蔓上跳下泰山。因为我是一个无名的特技演员,让伊斯特伍德看起来很好。熊巴纳比是我的名字,永远不要叫我杰克或詹姆斯,我会唱我的成名之路,熊巴纳比是我的名字。鸟儿们教我唱歌,当他们带我去见他们的国王时,首先我必须飞翔,在天空中飞得那么高,那么高,那么高,那么高,那么高,那么高,所以——如果你想这样唱,想想你想说什么,加上一首曲子,你就会看到,这是多么容易。崔克布丁、鱼和薯条、汽水和甘草、鲜花、河流、沙滩和大海、雪花和星星都是免费的。啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
},
新样本列数据{
Title=“Column2”,
内容=”只是好孩子,从来没有伤害过他们。你所见过的一切都被打败了,从他们出生的那一天起就被法律所困扰。在曲线上笔直,在山丘上平坦。总有一天山可能会得到他们,但法律永远不会。让他们走,这是他们知道的唯一方式,这只是比法律允许的多一点而已。很好老伙计们,如果可以的话,他们不会改变,像一个真正的现代罗宾汉一样与这个体系作战。骑士,一个进入一个不存在的人的危险世界的阴影飞行。迈克尔·奈特,一个年轻的独行侠,在一个罪犯凌驾于法律之上的世界里,为无辜者和无助者的事业进行十字军东征。我从不花太多时间我在学校教过很多女士。我确实是为了报酬才把我的身体租出去的,嘿嘿。我因为谢丽尔·蒂格斯被烧伤了,因为拉奎尔·韦尔奇被炸了。但是当我最后在干草里的时候,那只是干草,嘿嘿。我可能会跳一座敞开的吊桥,或者从藤蔓上跳下泰山。因为我是一个无名的特技演员,让伊斯特伍德看起来很好。熊巴纳比是我的名字,永远不要叫我杰克或詹姆斯,我会唱我的成名之路,熊巴纳比是我的名字。鸟儿们教我唱歌,当他们带我去见他们的国王时,首先我必须飞翔,在天空中飞得那么高,那么高,那么高,那么高,那么高,那么高,所以——如果你想这样唱,想想你想说什么,加上一首曲子,你就会看到,这是多么容易。崔克布丁、鱼和薯条、汽水和甘草、鲜花、河流、沙滩和大海、雪花和星星都是免费的。啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦
},
新样本列数据{
Title=“Column3”,
内容=”只是好孩子,从来没有伤害过他们。你所见过的一切都被打败了,从他们出生的那一天起就被法律所困扰。在曲线上笔直,在山丘上平坦。总有一天山可能会得到他们,但法律永远不会。让他们走,这是他们知道的唯一方式,这只是比法律允许的多一点而已。很好老伙计们,如果可以的话,他们不会改变,像一个真正的现代罗宾汉一样与这个体系作战。骑士,一个进入一个不存在的人的危险世界的阴影飞行。迈克尔·奈特,一个年轻的独行侠,在一个罪犯凌驾于法律之上的世界里,为无辜者和无助者的事业进行十字军东征。我从不花太多时间我在学校教过很多女人。我确实是为了报酬才把我的身体租出去的,嘿嘿。我被谢丽尔·蒂格斯烧死了,被拉奎尔·韦尔奇炸死了。但当我最后在干草里的时候,那只是干草,嘿嘿。我可能会跳一座敞开的吊桥,或者从藤蔓上跳下泰山。因为我是唯一的一个