WPF TextBlock la Liaison ne fonctionne pas
J'essaie de lier Text
propriété de TextBlock
pour mon bien, mais le texte n'est pas à jour.
XAML
<Window x:Name="window" x:Class="Press.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
Title="Press analyzer" Height="350" Width="525" ContentRendered="Window_ContentRendered"
d:DataContext="{d:DesignData MainWindow}">
...
<StatusBar Name="StatusBar" Grid.Row="2" >
<TextBlock Name="StatusBarLabel" Text="{Binding Message}"/>
</StatusBar>
</Window>
C#
public partial class MainWindow : Window, INotifyPropertyChanged
{
private string _message;
public string Message
{
private set
{
_message = value;
OnPropertyChanged("Message");
}
get
{
return _message;
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
où en êtes-vous du réglage de l'datacontext?
Je thint ce paramètre est
Je thint ce paramètre est
d:DataContext="{d:DesignData MainWindow}
OriginalL'auteur beta-tank | 2014-07-04
Vous devez vous connecter pour publier un commentaire.
Ensemble
DataContext
de MainWindow à lui-même dans le constructeur de MainWindow pour résoudre reliure:OU
Si vous ne définissez pas DataContext, vous avez à résoudre le liant explicitement à partir de XAML à l'aide de
RelativeSource
:Note - Vous pouvez toujours aller vérifier fenêtre de sortie de Visual Studio pour toute erreur de liaison.
OriginalL'auteur Rohit Vats