如何绑定字符串中的示例数据?

时间:2012-12-04 01:13:32

标签: c# windows-phone-7 windows-phone

我想将字符串绑定到示例数据。我可以绑定到代码隐藏,但随后它会在手机屏幕上闪烁,直到示例数​​据消失。我知道如何绑定到列表并在模拟预览中查看,我不知道在示例数据中创建字符串的语法。

以下是我的样本数据。我想为名为stringVar的变量添加一个属性。它只是一个字符串。

<local:ListPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ListPage" >

    <local:ListPage.stringVar />
    <local:ListPage.ItemList>
        <local:Book id="0" title="item 1"/>
    </local:ListPage.ItemList>
</local:ListPage>

1 个答案:

答案 0 :(得分:0)

我建议您在xaml中使用资源

<local:ListPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:ListPage" >
    <local:ListPage.Resources>
        <sys:String x:Key="MyStaticString">Hello world!<sys:String>
    </local:ListPage.Resources>

    <local:ListPage.stringVar />
    <local:ListPage.ItemList>
        <local:Book id="0" title="{StaticResource MyStaticString}"/>
    </local:ListPage.ItemList>
</local:ListPage>
相关问题