wpf-textbox-text verbindlich

ich versuche mich zu binden, den text einer textbox an ein property in meiner Klasse, und es funktioniert nicht, ich bin das Bearbeiten der Eigenschaft in der code-behind-aber ich sehe nicht, die Zeichenfolge in der textbox
dies ist die Klasse, und die Eigenschaft, die ich versuche zu binden, heißt songFolder.

public class song :  INotifyPropertyChanged
{
    public string title {get; set; }
    public string artist { get; set; }
    public string path { get; set; }
    public static string folder;
    public string songsFolder { get { return folder; } set { folder = value; NotifyPropertyChanged("songsFolder"); } }

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(String propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public song()
    {

    }

    public song(string title, string artist, string path)
    {
        this.title = title;
        this.artist = artist;
        this.path = path;
    }

}

und xaml, mit der Ressource und der textbox, die ich bin tring zu binden

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication1"
    Title="Song Filler" Height="455" Width="525">
<Window.Resources>
    <local:song x:Key="song"/>
</Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="auto"/>
        </Grid.ColumnDefinitions>
        <TextBox Name="browseBox" Text="{Binding Source={StaticResource ResourceKey=song}, Path=songsFolder, Mode=TwoWay}" Grid.Column="0"></TextBox>
        <Button Grid.Column="1" Width="auto" Click="Browse">browse</Button>
    </Grid>

--------------update----------------
Ich fügte hinzu, die nächste Zeile zu ctor dem Fenster:

BrowseBox.DataContext=new song()

Und beim Debuggen habe ich gesehen, dass die Eigenschaft verändert sich aber der text in der textbox nicht.

Ihre notify-Ereignis hat die falschen Eigenschaft: NotifyPropertyChanged("sPath"); Sollte NotifyPropertyChanged("songsFolder").
Danke, ich habe es geändert, aber es funktioniert immer noch nicht
Es könnte uns auch helfen, wenn du erklären, was falsch ist, außer eben "nicht funktioniert" ...
Ich fügte hinzu, Erklärungen
Aktualisiert xaml-update?

InformationsquelleAutor alostr | 2012-12-05

Schreibe einen Kommentar