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

标签 xaml windows-8 multiple-columns

Here描述了如何在 Windows 8 Metro 风格应用程序中创建具有水平滚动的多列文本。有没有办法添加“分栏符”以获得列顶部的任何标题,而不是中间(请记住,我们不知道每个部分中有多少列):

enter image description here

最佳答案

您可以创建一个 ItemsControl 并将 RichTextColumns 作为 DataTemplate。每列都在绑定(bind)到 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;
}

这是一个屏幕截图:
enter image description here

希望这可以帮助!

关于xaml - Windows 8 XAML 中的多列文本中的分栏符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10414793/

相关文章:

Python - 按多列索引对列表进行排序

python - 在Python中连接/组合相似的列

c# - 通用Windows App C#-导航到同一页面的新实例时缓存页面的实例(和状态)

xaml - 网格中一行的用户控件

javascript - 绑定(bind)到表的 Windows 8 Metro javascript 应用程序

multiple-columns - 使用单个查询重命名 netezza 中的两列

c# - 以下方法 : Identical. NameSpace.InitializeComponent() 和 Identical.NameSpace.InitializeComponent() 之间的调用不明确

c# - c# uwp 中的双重绑定(bind)

html - Mozilla (Windows 8) Sprite 图像加载问题

mysql - 如何将数据输入到 Windows 8 应用程序的 Web 服务中?