wpf zone de texte texte de liaison

je suis en train de lier le texte d'une zone de texte à un bien dans ma classe, et il n'est pas de travail, je suis modifiez la propriété dans le code derrière mais je ne vois pas la chaîne dans la zone de texte
c'est la classe, et le bien, je suis en train de liaison est appelée 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;
    }

}

et le xaml, contenant la ressource et de la zone de texte qui je suis tring pour lier

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

--------------mise à jour----------------
J'ai ajouté la ligne suivante à ctor de la fenêtre:

BrowseBox.DataContext=new song()

Et pendant le débogage, j'ai vu que la propriété est en train de changer, mais le texte dans la zone de texte n'est pas.

  • Votre événement de notification de la mauvaise propriété en elle: NotifyPropertyChanged("sPath"); Devrait être NotifyPropertyChanged("songsFolder").
  • Merci, je l'ai changé, mais il ne fonctionne toujours pas
  • Il pourrait nous aider, si vous expliquez ce qui ne va pas au-delà de simplement "ne pas travailler" ...
  • J'ai ajouté des explications
  • Mise à jour du xaml de mise à jour?
  • Je n'ai pas changé le code xaml
  • Êtes-vous d'obtenir toute erreur de liaison (regardez dans la fenêtre de sortie)? si oui, veuillez en fournir les détails. Il peut aussi vous aider si vous nous montrer le code-behind de la classe mainWindow (ou votre viewModel si vous êtes en utilisant MVVM).

InformationsquelleAutor alostr | 2012-12-05