sto cercando di associare il testo di una casella di testo a una proprietà nella mia classe e non funziona, sto modificando la proprietà nel codice sottostante ma non vedo la stringa nella casella di testo questa è la classe e la proprietà che sto tentando di associare si chiama songFolder.wpf textbox text binding
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;
}
}
e XAML, che contiene la risorsa e wich testo sto Tring per legare
<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- --------------- ho aggiunto la riga successiva alla ctor della finestra:
BrowseBox.DataContext=new song()
E durante il debug ho visto che la proprietà è c appeso ma il testo nella casella di testo non lo è.
tuo notificare evento ha la proprietà sbagliata in esso: 'NotifyPropertyChanged (" sPath ");' Dovrebbe essere 'NotifyPropertyChanged (" songsFolder ")'. – McGarnagle
Grazie, l'ho cambiato, ma non funziona ancora – alostr
Potrebbe aiutarci se spieghi cosa c'è che non va oltre "semplicemente non funziona" ... – McGarnagle