0

每当我测试我的应用程序时,它会绑定 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;
    }
}
4

1 回答 1

2

如果您指的Name是您在 first 中绑定的属性TextBlock,则它没有在您的对象中定义:

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

您可能打算Title改用。

于 2012-11-04T09:20:13.467 回答