我正在使用C#和XAML开发Metro风格的应用程序(适用于Windows 8).我已将我的viewmodels设置为用作设计时datacontexts,如下所示:
xmlns:vm="using:hub.ViewModels"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type=vm:ViewModels
Run Code Online (Sandbox Code Playgroud)
我的应用程序在运行时似乎运行正常,但在VS 2012和Blend的设计视图中,我偶尔会得到这个(无用的)错误消息:
An Exception was thrown. TargetException: Error in the application.
Stacktrace
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
InnerException: None
Run Code Online (Sandbox Code Playgroud)
这仅发生在设计视图-这意味着我不能设置周围的一切我INotifyPropertyChanged的()事件断点.
调试设计时错误的最佳方法是什么?
design-time blend microsoft-metro windows-8 visual-studio-2012
我已经实现了一个用户控件,可以让我快速构建几个类似的界面屏幕。基本上它定义了两个依赖属性MainContent,UserInteractions然后显示在可视化模板(a 中的 xaml ResourceDictionary)中,如下所示:
+-------------+
| L | |
| o | Main |
| g | Content |
| o | |
+---+---------+
| Interaction |
+-------------+
Run Code Online (Sandbox Code Playgroud)
屏幕的 Xaml 如下所示:
<controls:ScreenControl>
<controls:ScreenControl.MainContent>
<TextBlock>Some content goes here</TextBlock>
</controls:ScreenControl.MainContent>
<controls:ScreenControl.UserInteractions>
<Button>Do something</Button>
</controls:ScreenControl.UserInteractions>
</controls:InstallerScreenControl>
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,这很好用。但是,在设计器中,什么都看不到。不是视图中明确定义的内容,也不是模板中的内容。我需要添加什么才能启用设计支持?我尝试将模板移动到Themes/Generic.xaml某些地方的建议,但这没有区别。这个 SO 问题似乎相关,但没有得到有用的答案。
编辑:
我的ScreenControl样子:
public class ScreenControl : UserControl
{
public object MainContent
{
get { return GetValue(MainContentProperty); }
set { SetValue(MainContentProperty, value); }
} …Run Code Online (Sandbox Code Playgroud)