J'essaie de lier le texte d'une zone de texte à une propriété dans ma classe, et cela ne fonctionne pas, je modifie 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 la propriété que j'essaye de lier est appelée songFolder.wpf liaison de texte textbox
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 XAML, contenant la ressource et la zone de texte Wich je suis Tring 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>
-------------- update- --------------- J'ai ajouté la ligne suivante à cteur de la fenêtre:
BrowseBox.DataContext=new song()
Et pendant le débogage j'ai vu que la propriété est c suspendu mais le texte dans la zone de texte n'est pas.
Votre informer l'événement a la mauvaise propriété: 'NotifyPropertyChanged (" sPath ");' Devrait être 'NotifyPropertyChanged (" songsFolder ")'. – McGarnagle
Merci, je l'ai changé, mais il ne fonctionne toujours pas – alostr
Il pourrait nous aider si vous expliquez ce qui ne va pas au-delà de simplement "ne fonctionne pas" ... – McGarnagle