Question

Whenever I test my app.. it binds the data from Note class and displays it if it isn't a string. But for the string variables it wont bind. What am I doing wrong?

Inside my main:

    <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>

in code behind:

    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 = "";
            }
        }
    }

and

 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");
    }

notes class:

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;
    }
}

No correct solution

OTHER TIPS

If you're referring to the Name property that you're binding in the first TextBlock, it isn't defined in your object:

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

You probably meant to use Title instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top