[英]SQLite + Visual Studio 2013 Express - design-time Support issue
[英]Visual Studio 2013 WPF design-time data isn't displayed
我有一些在设计器中可以正常显示的UserControl,但是我无法对构造函数中的设计时示例内容进行任何更改。 似乎根本没有执行。
XAML:
<UserControl x:Class="Example.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock Name="testx" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"></TextBlock>
</Grid>
码:
using System.ComponentModel;
using System.Windows.Controls;
namespace Example
{
/// <summary>
/// Interaction logic for Test.xaml
/// </summary>
public partial class Test : UserControl
{
public Test()
{
InitializeComponent();
if (DesignerProperties.GetIsInDesignMode(this))
testx.Text = " IN DESIGN!";
}
}
}
我已经尝试了很多选项,但是仍然无法在WPF设计器中显示如何显示设计时数据:(不同的上下文绑定也什么也没有显示...
PS:在Win8上尝试了干净的VS2012和VS2013项目。 什么都没做! :(我不知道该怎么办,还没有在网上找到任何类似的东西...仅在构造函数中添加设计检查并设置现有的控制文本就足够了吗?
K,最简单的答案是:您在正确的道路上。
总的来说是:比这复杂一点。
如果放入另一个else testx.Text = RUNTIME;
,示例将像“ kinda”一样工作else testx.Text = RUNTIME;
在您if
,像这样:
if (DesignerProperties.GetIsInDesignMode(this))
testx.Text= " IN DESIGN!";
else
testx.Text= " Runtime";
您将在运行时看到所需的内容,但您的设计时间将为空。
在设计时,如果我没记错的话,还需要设置上下文。 如果您正在使用任何MVVM框架,则可以“免费”获得此功能。 与之类似,您将拥有“设计时”属性,并且可以设置设计所需的任何数据。 要注意的是,如果我的记忆正确,则需要有一个空的构造函数。 您还将使用绑定,而不是直接设置text属性。
我记得上次我在“香草” wpf中尝试执行类似的操作时缺少默认的WPF和绑定(例如,没有MVVM,没有绑定),但是我相信这有点儿破解这是可以实现的。 再说一次,我记不起来了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.