我在设计时与运行时如何呈现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) 我的设置: 我在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#和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
场景: 创建一个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)
要求:
问题:
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) 我编写了一个组件,它应该存储一些与项目目录相关的信息.每次更改组件的属性时,都应该写一个文件.那么组件如何在设计时确定当前项目目录.
提前致谢
编辑:
我想在每次更改组件的属性时生成delphi源文件,以便在编译代码时始终获得最新版本.可以把它想象成一种代码生成器.
目前我设置了存储源的整个路径和文件名,但我更喜欢项目的相对路径(或包含我的组件的表单/ datamodule),以便更容易在不同的开发人员机器上复制项目.
我在主窗体上有几个TPanel,我根据用户选择的选项显示/隐藏.问题是,在设计时我必须经常移动它们来编辑它们.是否有其他人处理这种情况的更容易/更好的方式?
好吧,我厌倦了这个问题.
我正在尝试创建UserControl,我可以从XAML填充其内容.以前我创建了ObservableCollection DependencyProperty.它在运行时工作,但在设计时出现了错误:
你调用的对象是空的.
现在我做了更简单的版本:
public partial class UC : UserControl
{
public UC()
{
Labels = new ObservableCollection<Label>();
InitializeComponent();
Labels.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Labels_CollectionChanged);
}
void Labels_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
foreach (Label uc in e.NewItems)
Container.Children.Add(uc);
}
private ObservableCollection<Label> _lables = new ObservableCollection<Label>();
public ObservableCollection<Label> Labels
{
get { return _lables; }
set { _lables = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我喜欢使用UserControll的方式
<Window x:Class="WpfApplication1.MainWindow"
xmlns:gsh="clr-namespace:WpfApplication1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Margin="0,0,0,30">
<gsh:UC x:Name="uC1">
<gsh:UC.Labels>
<Label Content="qwerty1" />
<Label Content="qwerty2" …Run Code Online (Sandbox Code Playgroud) wpf xaml design-time dependency-properties observablecollection
我已经创建了自定义控件.它有一个名为"Tab"的属性.此属性添加了一个"FloorsInformation"控件的集合,这些控件从"DockContainerItem"类继承到我的自定义控件.

现在,我想在单击Tab"CollectionEditor"窗口的"确定"按钮后,将"FloorsInformation"控件添加到我的自定义控件中.

我有"AddTabs"方法.但是,我不能在正确的地方称呼它.我必须在"Tab"属性的"set accessor"中调用"AddTabs"方法,但它永远不会发生.
我也可以从"Tab"属性的"get accessor"调用此方法,但是在"Tab"属性的"get accessor"中调用此方法将导致错误,因为程序访问"get accessor"的"Tab"属性不断.
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
[ToolboxItem(true), ToolboxBitmap(typeof(ToolboxIconResourceFinder), "FloorsGrouping.bmp")]
[DisplayName("Floors Group")]
[Editor("WindowsFormsControlLibrary2.FloorsGrouping, WindowsFormsControlLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=197889249da45bfc", typeof(UITypeEditor))]
[Description("Floorssssssss")]
[Category("Saino")]
[DefaultProperty("Text")]
[DesignerCategory("Component")] //Form //Designer //Empty String ("")
public partial class FloorsGrouping : Bar
{
private Tabs tabs = new Tabs();
public FloorsGrouping()
{
InitializeComponent();
this.AutoHide = true;
}
[Category("Data")]
[DisplayName("Tabs")]
[Description("Tabsssssssssssss")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(ItemsCollectionEditor), typeof(UITypeEditor))]
public Tabs Tab
{
get
{
//AddTabs();
return tabs;
}
//set
//{
//AddTabs();
//}
}
public void AddTabs()
{
foreach (DockContainerItem dciItem …Run Code Online (Sandbox Code Playgroud) 我无法找到以下问题的任何信息:有没有在设置宽度列QTableWidget的可能性设计时.当我ui在文本编辑器中打开-file时,我发现,列的声明如下:
<column>
<property name="text" >
<string>My column name</string>
</property>
</column>
Run Code Online (Sandbox Code Playgroud)
我试图添加一些属性width,但没有成功.
我在qtcentre.org找到的唯一问题是这个.但不幸的是,它没有答案.
谢谢你的建议(即使它是"你不能").
PS请不要回答,我可以在运行时这样做:
table->headerView()->resizeSection( columnIdx, width );
Run Code Online (Sandbox Code Playgroud) 我正在编写一个自定义组件编辑器,基本上类似于TActionList编辑器,因为它允许创建子组件.编辑器具有添加/删除组件的按钮.
现在,我想知道是否继承了所选组件,以便我可以禁用删除按钮.我没有在IDesigner相关接口中找到任何此类成员.
如果我继续删除,Designer.DeleteSelection(True);那么我得到一个例外:
选择包含在祖先中引入的组件xxx,不能删除.
这不是太糟糕,但我宁愿首先禁用删除按钮.
design-time ×10
c# ×3
delphi ×3
wpf ×3
runtime ×2
winforms ×2
xaml ×2
blend ×1
components ×1
delphi-2010 ×1
designer ×1
ide ×1
qt ×1
qtablewidget ×1
styles ×1
triggers ×1
windows-8 ×1