Default value at design time XAML

心已入冬 提交于 2019-12-03 22:18:59
Scroog1

If you would prefer a less verbose version of Ian Bamforth's answer, you can just do

<TextBlock Text="{Binding MyText, FallbackValue=None}"/>
IBam

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

user3618238

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!