WP7数据绑定显示int但不显示字符串?

时间:2012-11-04 04:56:36

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

每当我测试我的应用程序时...它会绑定来自Note类的数据,如果它不是字符串则显示它。但对于字符串变量,它不会绑定。我做错了什么?

在我的主要内容中:

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <ListBox x:Name="Listbox" SelectionChanged="listbox_SelectionChanged" ItemsSource="{Binding}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Border Width="800" MinHeight="60">
                        <StackPanel>
                            <TextBlock x:Name="Title" VerticalAlignment="Center" FontSize="{Binding TextSize}"  Text="{Binding Name}"/>
                            <TextBlock x:Name="Date"  VerticalAlignment="Center" FontSize="{Binding TextSize}"  Text="{Binding Modified}"/>
                        </StackPanel>
                    </Border>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Grid>
代码背后的

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        MessageBox.Show("enters onNav Main");
        DataContext = null;
        DataContext = Settings.NotesList;


        Settings.CurrentNoteIndex = -1;
        Listbox.SelectedIndex = -1;


        if (Settings.NotesList != null)
        {
            if (Settings.NotesList.Count == 0)
            {
                Notes.Text = "No Notes";
            }
            else
            {
                Notes.Text = "";
            }
        }
    }

 public static class Settings
 {
    public static ObservableCollection<Note> NotesList;
    static IsolatedStorageSettings settings;
    private static int currentNoteIndex;

    static Settings()
    {
        NotesList = new ObservableCollection<Note>();
        settings = IsolatedStorageSettings.ApplicationSettings;
        MessageBox.Show("enters constructor settings");
    }

备注课程:

public class Note
{
    public DateTimeOffset Modified { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
    public int TextSize { get; set; }

    public Note()
    {
        MessageBox.Show("enters Note Constructor");
        Modified = DateTimeOffset.Now;
        Title = "test";
        Content = "test";
        TextSize = 32;
    }
}

1 个答案:

答案 0 :(得分:2)

如果您在第一个Name中引用了您要绑定的TextBlock属性,则不会在您的对象中定义它:

public DateTimeOffset Modified { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int TextSize { get; set; }

您可能打算使用Title代替。