Hallo,
ich verzweifle so langsam an der doch recht einfachen Aufgabe ein TextBlock an eine Eigenschaft (Property) einer Klasse zu binden.
Bei meinem Testprojekt handelt es sich um ein Visual Studio 2015 Projekt.
Ich erlaube mir mal meinen Code hier zu posten, in der Hoffnung dass jemand den Fehler findet.
Hier die Klasse:
Mainwindow xaml:
Mainwindow Code benind:
Wie man an den aus kommentierten Zeilen erkennen kann hab ich schon so manches probiert. Leider ohne Erfolg....
So, jetzt kann ich nur hoffen, dass ihr so früh am Samstagmorgen schon fit für dies Aufgabe seid....
Vielen Dank im Voraus,
Jeiss
ich verzweifle so langsam an der doch recht einfachen Aufgabe ein TextBlock an eine Eigenschaft (Property) einer Klasse zu binden.
Bei meinem Testprojekt handelt es sich um ein Visual Studio 2015 Projekt.
Ich erlaube mir mal meinen Code hier zu posten, in der Hoffnung dass jemand den Fehler findet.
Hier die Klasse:
VB.NET-Quellcode
- Imports System.ComponentModel
- Public Class MyTestClass
- Implements INotifyPropertyChanged
- Private customerNameValue As String ' = "EMPTY"
- 'Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
- 'Private Sub NotifyPropertyChanged(ByVal info As String)
- ' RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
- 'End Sub
- Public Property CustomerName() As String
- Get
- Return Me.customerNameValue
- End Get
- Set(ByVal value As String)
- If Not (value = customerNameValue) Then
- Me.customerNameValue = value
- 'NotifyPropertyChanged("CustomerName")
- OnPropertyChanged("CustomerName")
- End If
- End Set
- End Property
- Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
- Private Sub OnPropertyChanged(ByVal prop As String)
- RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(prop))
- End Sub
- End Class
Mainwindow xaml:
XML-Quellcode
- <Window x:Class="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"
- xmlns:local="clr-namespace:Notification_Test"
- mc:Ignorable="d"
- Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
- <!--<Window.Resources>
- <local:MyTestClass x:Key="whyareyounotworking" />
- </Window.Resources>-->
- <Window.DataContext>
- <local:MyTestClass />
- </Window.DataContext>
- <Grid>
- <!--<Grid.DataContext>
- <local:MyTestClass />
- </Grid.DataContext>-->
- <Border><!--DataContext="whyareyounotworking"-->
- <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="55,35,0,0" TextWrapping="Wrap" Width="80" Background="Coral" VerticalAlignment="Top"
- Text="{Binding CustomerName}">
- </TextBlock>
- </Border>
- <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="55,150,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="145" />
- <Button x:Name="button" Content="Go" HorizontalAlignment="Left" Margin="245,154,0,0" VerticalAlignment="Top" Width="75" />
- </Grid>
- </Window>
Mainwindow Code benind:
Wie man an den aus kommentierten Zeilen erkennen kann hab ich schon so manches probiert. Leider ohne Erfolg....
So, jetzt kann ich nur hoffen, dass ihr so früh am Samstagmorgen schon fit für dies Aufgabe seid....
Vielen Dank im Voraus,
Jeiss