WPF-TextBlock-Bindung nicht funktioniert
Ich versuche binden Text
Eigenschaft von TextBlock
meiner Eigenschaft text aber nicht aktualisiert.
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));
}
}
- wo sind Sie, die Einstellung der datacontext?
- Ich thint diese Einstellung ist
d:DataContext="{d:DesignData MainWindow}
Du musst angemeldet sein, um einen Kommentar abzugeben.
Set
DataContext
von MainWindow zu sich in den Konstruktor von MainWindow zu beheben Bindung:ODER
Wenn Sie nicht setzen DataContext, die Sie lösen müssen verbindlich ausdrücklich von XAML mit
RelativeSource
:Hinweis - Sie können jederzeit gehen und überprüfen Sie die Ausgabe-Fenster von Visual Studio für alle verbindliche Fehler.