标签: design-time

RTTI可以在设计时从项目代码中查询类型吗?

我想使用RTTI在设计时而不是运行时检查项目源文件中包含的类型.

据我所知,这是不受支持的,但是这个问题的评论中的讨论表明它可能并且已经有几个Delphi版本.这是我第一次听说这个功能可用但是我一直无法为自己重现它.

这是我的测试示例.它使用一个简单的TListBox后代TMyListBox,它具有一个string属性TypeToExplore,该属性在设置时使用输入的限定类型名称的属性填充列表框.

unit MyListBox;

interface

uses
  SysUtils, Classes, Controls, StdCtrls;

type
  TMyListBox = class(TListBox)
  private
    FTypeToExplore : string;
    procedure SetTypeToExplore(const inValue: string);
    procedure FillWithTypeDetails;
  published
    property TypeToExplore : string read FTypeToExplore write SetTypeToExplore;
  end;

procedure Register;

implementation

uses
  RTTI, TypInfo;

procedure TMyListBox.SetTypeToExplore(const inValue: string);
begin
  if inValue = FTypeToExplore then
    Exit;

  FTypeToExplore := inValue;
  Clear;
  FillWithTypeDetails;
end;

procedure TMyListBox.FillWithTypeDetails;
var
  context : TRTTIContext;
  theType : TRttiType;
  properties …
Run Code Online (Sandbox Code Playgroud)

delphi design-time rtti

10
推荐指数
1
解决办法
567
查看次数

在WPF中设计时间数据

[使用vs2010和表达式混合v4]

嗨 - 尝试在WPF和Blend中加载一些设计时数据,使用Josh Smith的概念:http://joshsmithonwpf.wordpress.com/2010/04/07/assembly-level-initialization-at-design-time/ eg

[AttributeUsage(AttributeTargets.Assembly)]
public class DesignTimeBootstrapperAttribute : Attribute
{
    public DesignTimeBootstrapperAttribute(Type type)
    {
        var dep = new DependencyObject();
        Debug.WriteLine("here..?");
        if (DesignerProperties.GetIsInDesignMode(dep))
        {
            // TODO: Design-time initialization…
            IBootstrapper instance = Activator.CreateInstance(type) as IBootstrapper;
            if (instance != null)
            {
                instance.Run();
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的属性在AssemblyInfo.cs中,AppBootstrapper扩展了MefBootstrapper.

[assembly: AssemblyCopyright("Copyright ©  2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: DesignTimeBootstrapper(typeof(AppBootstrapper))]
Run Code Online (Sandbox Code Playgroud)

我不想使用Blend样本数据,a)因为它似乎没有为ObservableCollection创建数据而b)我按照定义处于设计模式,因此事情会发生很大变化,但我的'生成的数据' 将不会.

无论如何,似乎没有任何事情发生.

Q1:如何调试我的bootstrapper的设计时初始化?Q2:我的View XAML中是否需要额外的混合命名空间/属性等?

(在我的引导程序中,我只是注册了一个不同的模块,我想用DesignTimeService替换RunTimeService,导出IService接口).

TIA

wpf design-time mvvm expression-blend

8
推荐指数
1
解决办法
1760
查看次数

检测WP7代码中的DesignTime

简单的问题,有没有人知道如何检测代码是否与WP7执行设计时?HtmlPage.IsEnabled的常用Silverlight解决方案在此上下文中不起作用.

design-time windows-phone-7

8
推荐指数
1
解决办法
890
查看次数

如何在后续代中禁用派生类中的设计器

为了在类中禁用组件设计器,只需向其添加[System.ComponentModel.DesignerCategory("")]属性即可,但它不适用于任何代中从此类派生的任何类.例如:

[System.ComponentModel.DesignerCategory("")]
public class A:ServiceBase { } //Designer is disabled here

public class B:A {} //Designer is enabled here

[System.ComponentModel.DesignerCategory("")]
public class B:A {} //Designer is enabled here too

[System.ComponentModel.DesignerCategory("Code")]
public class B:A {} //Designer is enabled even here
Run Code Online (Sandbox Code Playgroud)

当然,这发生在任何其他世代和排列中.例如

//Whatever attribute here
public class C:B {} //Designer is enabled here
Run Code Online (Sandbox Code Playgroud)

有没有人试图摆脱它?为什么组件模型尝试添加设计器支持,即使它在第一代中明确禁用?

谢谢

c# inheritance design-time componentmodel visual-studio

8
推荐指数
1
解决办法
2740
查看次数

WPF用户控件会引发设计时异常

我有一个userControl启动一个计时器.看起来XAML设计师试图调用该代码,该代码链接到一些后端数据库的东西.我一直在设计屏幕上得到一个无法解决的异常错误.

任何想法如何阻止设计师试图运行代码?

c# wpf design-time

8
推荐指数
1
解决办法
2211
查看次数

如何在设计模式下调试WPF用户控件?

我有一个我创建的包含标签的wpf用户控件.标签的前景设置根据检查许多条件的某些代码而更改.在我的控制标签显示的是错误的颜色在设计时,但我无法弄清楚如何调试在设计时我的用户控件,以便我可以把它赶断点(因而揣摩出我的逻辑是有缺陷的).控件上的颜色在运行时是正确的,只有在设计时它才会显示不正确.

c# wpf user-controls design-time visual-studio

8
推荐指数
1
解决办法
2329
查看次数

WPF设计时与运行时风格的差异与触发器

我在设计时与运行时如何呈现XAML存在很大问题.在大多数情况下,事情是一致的,但是当我使用任何具有触发器的样式时,触发器不会在设计时检查.

下面是一个示例应用程序,用于显示事物的显示方式:

<Window x:Class="DesignDifferencesWithDesignAndRuntime.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="400" Width="400">
<Window.Resources>
    <Style x:Key="multiLineInTrigger" TargetType="{x:Type TextBox}">
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Width" Value="150" />
        <Setter Property="Height" Value="22" />
        <Setter Property="BorderBrush" Value="Blue" />
        <Setter Property="BorderThickness" Value="2" />
        <Style.Triggers>
            <Trigger Property="AcceptsReturn" Value="True">
                <Setter Property="Width" Value="Auto" />
                <Setter Property="Height" Value="Auto" />
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="VerticalAlignment" Value="Stretch" />
            </Trigger>
        </Style.Triggers>
    </Style>
    <Style x:Key="singleLineInTrigger" TargetType="{x:Type TextBox}">
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="Width" Value="Auto" />
        <Setter Property="Height" Value="Auto" />
        <Setter Property="HorizontalAlignment" Value="Stretch" …
Run Code Online (Sandbox Code Playgroud)

wpf triggers styles design-time runtime

7
推荐指数
1
解决办法
2432
查看次数

在Visual Studio中设计时在设计时单击按钮?

我的设置: 我在Visual Studio 2008中有一个C#应用程序(.NET 3.5).没有机会切换到WPF或者无论如何:).

我的应用程序包含一个自定义控件(从Windows.Forms.Button派生的按钮类),它可以替代Windows.Forms.TabControl.我可以将这些按钮相互关联,每个按钮可以与它正在处理的一个控件相关联(通常是某种类型的Windows.Forms.Panel).它看起来像这样:

public class TabButton : System.Windows.Forms.Button
{
    // ...
    protected override void OnClick(EventArgs e)
    {
        base.OnClick(e);
        this.myAssociatedControl.Visible = true;
        this.tellMyBuddiesToHideTheirControls();
    }
    // ...
}
Run Code Online (Sandbox Code Playgroud)

基本上它只是单击一个按钮,显示其绑定控件并使绑定到相关按钮的控件消失 - 就像TabControl一样,但该方法很容易设计,我可以将按钮放在远离其内容面板的位置.

问题: 这在运行时非常有效,但在设计时的使用可以说是奇怪的:使用鼠标,找到属于该组的控件并运行一系列<Send To Back>s直到所需的控件可见.

问题: 有没有办法告诉VS设计师在设计时评估按钮的点击次数,就像使用TabControl一样,这样我就可以像在运行时一样点击它们来切换标签?

我一直在寻找相当长的一段时间.这里有一些文章,但它们似乎只是为了向属性设计师添加其他属性.

c# design-time custom-controls visual-studio winforms

7
推荐指数
1
解决办法
2122
查看次数

VS2012/Blend 5:调试在设计视图中发生的异常(仅)

我正在使用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

7
推荐指数
2
解决办法
3286
查看次数

WPF MarkupExtension和RowDefinition导致NotImplementedException

场景: 创建一个MarkupExtension,用Grid.Row ="{namespace:ClassExtension GridRowName}"替换Grid.Row ="0"(列相同)

Xaml代码:

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition Height="Auto" x:Name="TitleRow" />
    <RowDefinition Height="Auto" x:Name="LastNameRow" />
    <RowDefinition Height="Auto" x:Name="FirstNameRow" />
    <RowDefinition Height="Auto" x:Name="EmailRow" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition x:Name="LabelColumn" />
    <ColumnDefinition x:Name="ValueColumn" />
  </Grid.ColumnDefinitions>

    <Label Grid.Row="{me:GridDefinition Name=TitleRow}" Grid.ColumnSpan="2" FontWeight="Bold" FontSize="14" />
    <Label Grid.Row="{me:GridDefinition Name=LastNameRow}" Grid.Column="{me:GridDefinition Name=LabelColumn}" FontWeight="Bold" FontSize="14" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

要求:

  • 使用incorrent GridRowName(或columnName)时显示XAML错误
  • 使用正确的GridRowName(或columnName)时,不显示XAML错误
  • 当Valid ColumnName用于Row声明(和vica verca)时,应显示XAML错误

问题: Grid.Column的一切正常,但Grid.Row总是在设计时抛出"未实现的异常"(grid.row带下划线,grid.column不是). 在此输入图像描述

行和列都命名正确,但行始终显示错误.如果我们指定一个无效的列名,该列会显示一个错误(这是预期的,因此Grid.Column工作正常!) 在此输入图像描述

如您所见,列工作正常,但行不行.问题出在名为GridDefinitionExtension的MarkupExtension中:

[MarkupExtensionReturnType(typeof(int))]
public class GridDefinitionExtension : MarkupExtension
{
    public string Name { private get; set; }

    public override object ProvideValue(IServiceProvider serviceProvider) …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml design-time markup-extensions

7
推荐指数
1
解决办法
651
查看次数