将变量绑定到RichTextBlock的Text属性(在RichTextColumns中)

时间:2013-06-15 00:34:43

标签: windows-store-apps

我正在尝试将变量绑定到RichTextBlock的Text属性,但内容未显示。 RichTextBlock位于公共文件夹中的RichTextColumns元素内。

我的Xaml代码: -

<Page
x:Class="Test_Menu.TopicDetailsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test_Menu"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:common="using:Test_Menu.Common"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <!-- Content is allowed to flow across as many columns as needed -->
    <common:RichTextColumns x:Name="richTextColumns" >
        <RichTextBlock x:Name="richTextBlock" Width="300" Height="700" Style="{StaticResource ItemRichTextStyle}" IsTextSelectionEnabled="False" >
            <Paragraph>
                <Run FontWeight="Normal" Text="{Binding sTitle}" Foreground="White" />
            </Paragraph>
        </RichTextBlock>

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

</Grid>

我的代码背后 -

namespace Test_Menu

{  public sealed partial class TopicDetailsPage:Page     {         public string sTitle {get;组; }

    public TopicDetailsPage()
    {
        sTitle = "Test Text";
        this.InitializeComponent();
        richTextBlock.DataContext = sTitle; //name of richTextBlock

    }

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
    }
}

}

出局空白。任何帮助都将受到高度赞赏。

0 个答案:

没有答案