问题
I have a binded TextBlock
, XAML:
<TextBlock Text="{Binding MyText}"/>
I know the FallbackValue
can be used if the Binding isn't available, but this happens at run time ? Is there any way to show a default value at design time ? It would make things easier if I could see a value when designing my windows instead of an empty TextBlock
.
Thanks
回答1:
If you would prefer a less verbose version of Ian Bamforth's answer, you can just do
<TextBlock Text="{Binding MyText, FallbackValue=None}"/>
回答2:
Adapting an example from this question.
This works for me - the text "None" is shown in the designer:
<TextBlock>
<TextBlock.Text>
<Binding ElementName="root" Path="blah" FallbackValue="None" />
</TextBlock.Text>
</TextBlock>
Hope that helps
回答3:
If you have this data bound and are using the MVVM architecture then setting a DEFAULT value for the model item it is bound to will display the value at design time
I am just using:
Model.cs:
private int frame = 999999;
public int Frame
{
get { return frame; }
set
{
frame = value;
NotifyPropertyChanged(m => m.Frame);
}
}
and in my XAML:
<TextBlock Text="{Binding Path=Frame}" />
and the default value of "999999" is being displayed in the designer
来源:https://stackoverflow.com/questions/17208665/default-value-at-design-time-xaml