Victor Chelaru
Victor Chelaru

Reputation: 4837

How an I set a default Label value when binding its Content in WPF

I have a Label defined in XAML as follows:

<Label Content="{Binding Name}"></Label>

The problem is that the label is invisible in the XAML editor and I'd like it to have a default value there so that the editor accurately reflects what will show up at runtime.

Is there a way to give it a value in XAML which will show up in the editor, but then use the binding at runtime?

Upvotes: 5

Views: 4311

Answers (2)

pushpraj
pushpraj

Reputation: 13679

Here you go

FallbackValue is the answer for the same

example

<Label Content="{Binding Name, FallbackValue=Default}"></Label>

Upvotes: 11

A. S. Mahadik
A. S. Mahadik

Reputation: 625

You also assign the default value to name of its viewmodel.cs file in its constructor

Upvotes: 1

Related Questions