I'm an experienced C# developer but a WPF newbie. Basic question (I think) that I can't find an answer to by web searching. Here's the simplified use case...
I want to display a string in a WPF TextBlock. So I write some C# code in codebehind of my XAML control...
public class MyCoolControl : UserControl
{
public void InitializeMyCoolControl()
{
this.DataContext = "SomeStringOnlyAvailableAtRuntime"; // Perhaps from a database or something...
}
}
And I set up my XAML like this:
<UserControl ... snip...>
<!-- Bind the textblock to whatever's in the DataContext -->
<TextBlock Text="{Binding}"></TextBlock>
</UserControl>
Works great, I can see the value "SomeStringOnlyAvailableAtRuntime" when I execute my application. However, I don't see anything at Design Time using Visual Studio 2008's XAML Designer.
How can I see a placeholder value (anything) for the textblock at design time?
Thanks!
-Mike
I often use FallbackValue
on the binding to have something to look at while I design user controls. For example:
<TextBlock Text={Binding Path=AverageValue, FallbackValue=99.99} />
However, since FallbackValue
is not just applied at design time, this might not be appropriate if you want to use FallbackValue
at run time for other reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With