TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Giovanbattista Barra
NA
98
18.6k
How to bind multiple TextBoxes on one label
Dec 30 2019 12:15 PM
For my exercise:
I have to concat the values of two input fields (string), in order to show them - through a binding object - in a Label
Here the XAML Code:
<div>We published plenty of articles, blogs, videos,
in
the year 2019 under different categories. Thank you, authors,
for
all the contributions.</div>
<div> </div>
<div>Here are the top 20 C# Corner authors based on the number of articles, blogs, videos, and total points earned
in
the year 2019.</div>
<Grid>
<TextBox x:Name=
"txtFirstName"
HorizontalAlignment=
"Left"
Height=
"45"
Margin=
"35,84,0,0"
TextWrapping=
"Wrap"
VerticalAlignment=
"Top"
Width=
"144"
Text=
"{Binding ConcatFullName, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
/>
<TextBox x:Name=
"txtLastName"
HorizontalAlignment=
"Left"
Height=
"45"
Margin=
"210,84,0,0"
TextWrapping=
"Wrap"
VerticalAlignment=
"Top"
Width=
"144"
Text=
"{Binding ConcatFullName, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
/>
<Label x:Name=
"lblConcat"
Content=
"Name Verkettung"
HorizontalAlignment=
"Left"
Margin=
"403,53,0,0"
VerticalAlignment=
"Top"
FontSize=
"16"
FontFamily=
"Segoe UI Black"
/>
<Label x:Name=
"lblConcatTheFullName"
HorizontalAlignment=
"Left"
Margin=
"403,84,0,0"
VerticalAlignment=
"Top"
Width=
"144"
Foreground=
"#FF002DFF"
FontSize=
"14"
Height=
"45"
Content=
"{Binding ConcatFullName}"
/>
</Grid>
INotifyPropertyChanged with Method FullName
public
class
FullName : INotifyPropertyChanged
{
private
string
_ConcatFullName;
public
string
ConcatFullName
{
get
{
return
_ConcatFullName; }
set
{
if
(_ConcatFullName != value)
{
_ConcatFullName = value;
INotifyPropertyChanged(
"ConcatFullName"
);
}
}
}
File XAML.cs
//Here I implement a method to show on the UI the concat of two strings in a label
public
MainWindow()
{
InitializeComponent();
this
.DataContext = txtFirstName;
this
.DataContext = txtLastName;
lblConcatTheFullName.DataContext = FullName();
}
private
string
FullName()
{
return
this
.txtFirstName +
" "
+
this
.txtLastName;
}
Unfortunately I don't get the desired result. What is wrong with the data Binding?
Is there any other confortable way to solve this problem?
Any help please?
Many thanks in advance.
Best regards
Johannes
Reply
Answers (
2
)
How to background save automatically for every 5 mint in c#
how to handle stackpanel mousedown event