Bir metin kutusunun metnini sınıfımdaki bir özelliğe bağlamaya çalışıyorum ve bu çalışmıyor, özelliği koddaki arkaplanda düzenliyorum ancak metin kutusundaki dizeyi göremiyorum Bu sınıftır ve bağlamaya çalıştığım özellik songFolder olarak adlandırılır. kaynak ve ben bağlamak için tring am metin kutusu wich içeren 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;
}
}
ve xaml
,<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- --------------- Ben pencerenin ctor sonraki satırı eklendi:
BrowseBox.DataContext=new song()
Ve ayıklarken ederken mülkiyet c olduğunu gördük asılı ama metin kutusundaki metin değil.
Sizin bildirmek:
Daha sonra güncelleme metin kutusu bulma olayda yanlış özellik var: 'NotifyPropertyChanged (" sPath ");' NotifyPropertyChanged ("songsFolder") 'olmalıdır. – McGarnagle
Teşekkürler, ben değişti, ama hala çalışmıyor – alostr
Sadece neyin yanlış olduğunu açıklamanızın sebebi "işe yaramıyor" diye bize yardımcı olabilir ... – McGarnagle