How to see design-time data-binding in XAML editor (it works in runtime)?

后端 未结 2 1822
悲哀的现实
悲哀的现实 2020-12-03 04:56

I data-binded version number to appear as follows:

 DataContext=\"{Binding RelativeSource={RelativeSource Self}}\">
    

        
2条回答
  •  误落风尘
    2020-12-03 05:02

    Short answer, you can't do it that way. VS designer is not executing runtime code and your binding will not be resolved in design time. But there is support for design time data through d:DesignData extension.

    You can set design data context this way:

    
    
        
            Version is: 
            
            and advancing...
        
    
    

    d:DataContext={d:DesignData.... sets the desing time DataContext that will be used to resolve bindings in VS designer surface. You can set it to a xaml file that contains your sample data. Sample xaml file should be built with "DesignData" build action.

    See more here: http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/sample-data-in-the-wpf-and-silverlight-designer.aspx

提交回复
热议问题