好吧,我厌倦了这个问题.
我正在尝试创建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
我无法找到以下问题的任何信息:有没有在设置宽度列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) [编辑]要清楚,我知道如何通过反思获得表格列表.我更关心设计时属性网格.
我有一个用户控件具有Form类型的公共属性.
我希望能够在设计时从下拉菜单中选择一个表单.
我想从set命名空间填充表单下拉列表:UI.Foo.Forms
如果您拥有Control的公共属性,这将起作用.在设计时,属性将自动使用表单上的所有控件填充下拉列表,供您选择.我只想用命名空间中的所有表单填充它.
我该怎么做呢?我希望我足够清楚,所以没有混乱.如果可能的话,我正在寻找一些代码示例.当我有其他截止日期要求时,我试图避免花太多时间在这上面.
感谢您的帮助.
在我的桌面应用程序中,之前我已经设计了表单并执行了十次,但后来我对表单进行了细微的更改。但即使在更改之后,当我现在运行程序时,也会显示以前创建的表单。
可能是什么问题...有人可以帮助我吗?
Visual Studio 2010 可视化设计器是否允许在设计时通过外部 XML 文件加载数据?
看来我可以通过 d:DataContext 添加它,但是我有很多数据,通过 XML 加载它更容易。那么这可能吗?
我正在为WPF和Silverlight开发自定义控件.此控件具有抽象的复杂类型的collection属性,如下所示:
public Collection<MyBase> Configuration
{
get { return (Collection<MyBase>)GetValue(ConfigurationProperty); }
set { SetValue(ConfigurationProperty, value); }
}
// Using a DependencyProperty as the backing store for Configuration This enables animation, styling, binding, etc...
public static readonly DependencyProperty ConfigurationProperty =
DependencyProperty.Register("Configuration", typeof(Collection<MyBase>), typeof(MyControl), new PropertyMetadata(new ObservableCollection<MyBase>()));
Run Code Online (Sandbox Code Playgroud)
我的问题是我无法在Visual Studio 2010的设计器中向此属性添加新项目,因为它不知道任何派生类型的MyBase.
有没有办法向设计师注册这些类型?编辑器可以正常使用现有项目,并可以删除和修改它们.一张图片来说明:

我有UserControl显示文件信息。我想使用视图模型模拟在 Visual Studio 设计器中查看测试文件信息。这是 XAML:
<Label Content="{Binding DateCreated}"/>
Run Code Online (Sandbox Code Playgroud)
视图模型:
internal class ViewModel
{
public ViewModel(string pathToFile)
{
var file = new FileInfo(pathToFile);
this.DateCreated= file.CreationTime.ToShortDateString();
}
public string DateCreated{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在设计时,我使用视图模型模拟类在设计器中看到真实的文件信息:
internal class ViewModelMock : ViewModel
{
public ViewModelMock() : base(@"D:\Images\mock.png")
{
}
}
Run Code Online (Sandbox Code Playgroud)
我通过d:DataContext和插入模拟到xaml d:DesignInstance:
<UserControl ...
xmlns:mocks="clr-namespace:Company.Product.Mocks"
d:DataContext="{d:DesignInstance mocks:ViewModelMock, DesignTimeCreatable=True}">
Run Code Online (Sandbox Code Playgroud)
它有效,但问题出在这个@"D:\Images\mock.png" 硬编码的 value 中。一旦解决方案由 TFS 提供支持,我需要将图像放入项目中,并从ViewModelMock, 相对于项目路径引用此图像。
我怎样才能做到这一点?
像获取当前工作目录这样的简单方法给出了“ C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE ”,我猜是因为这是负责 Visual …
我注意到在选择多个项目时,一些属性会从Object Inspector中消失.
为什么会发生这种情况以及如何在创建组件时控制此行为?
例:
将2个按钮(TButton)添加到表单并选择其中一个.
在Object Inspector中,您可以看到所有TButton已发布的属性(请注意,还有Constraints属性).
将另一个按钮添加到当前选择(Shift按键时单击).
如您所见,Object Inspector中隐藏了一些属性(请注意,Constraints不再可见).
我正在尝试在 UserControl 中使用设计时 DataContext。根据这篇文章(以及本网站上的一些帖子),应该可以在 UserControl 标记本身中使用设计时 DataContext。
但是它对我不起作用,无论是在 UserControl 的还是在根元素的标签中。
UserControl(和模型视图模型)非常简单。一堆原始类型绑定到一些文本块和滑块。
我的用户控件看起来像:
<UserControl mc:Ignorable="d"
d:DataContext="{d:DesignInstance mockups:PrototypeMockup}">
<GroupBox DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=Prototype}" Header="{Binding Name}" >
...
<Image Source="{Binding Image}" />
<TextBlock Text="{Binding Size, StringFormat={}{0} mm}" />
<Slider Minimum="10" Maximum="80" Value="{Binding Size}" IsEnabled="{Binding IsEditing}" />
<TextBlock Text="{Binding Threshold}" />
<Slider Minimum="0" Maximum="255" Value="{Binding Threshold}" IsEnabled="{Binding IsEditing}" />
<TextBlock Text="{Binding BlockSize, StringFormat={}{0} px}" />
<Slider Minimum="10" Maximum="200" Value="{Binding BlockSize}" IsEnabled="{Binding IsEditing}" />
...
Run Code Online (Sandbox Code Playgroud)
模型视图模型如下所示:
public class PrototypeMockup
{
public string …Run Code Online (Sandbox Code Playgroud) 我查过这个问题,但其他答案都不适合我。
我在 VS2019 的错误列表中收到重复的消息。我不认为这是每个错误,当我第一次打开我的项目时,它不会这样做,但一旦我打开 XAML 文件,它就会保持这样。引发错误的代码不需要以任何方式与 XAML 文件交互(它发生在新创建的类上)。
一个答案说这可能是 IntelliSense 和编译器报告相同的错误,但我一直在使用IntelliSense + Compiler,这个问题只出现了大约 1-2 个月。另外,我切换到IntelliSense Only但仍然遇到双重错误。
重复项总是来自XamlInProcLanguageClient,但当我用谷歌搜索时,谷歌搜索显示单个结果。
附加信息:
我认为我在大约 1-2 个月前所做的唯一可能影响此问题的事情是我下载了 VS 2022 预览版(2.1 或 3)。但是,我从未真正打开过它并卸载了它以尝试解决问题(没有运气)。
design-time ×10
c# ×6
wpf ×4
properties ×2
xaml ×2
.net ×1
components ×1
delphi ×1
intellisense ×1
mvvm ×1
qt ×1
qtablewidget ×1
winforms ×1