Tag: 自定义控件

重建用户控件时,用户控件自定义属性会丢失状态

我有一个自定义属性的用户控件,如下所示: [DefaultValue(true)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] [Description(“Gets or sets whether the \”Remove\” button is visible.”)] public bool ShowRemoveButton { get { return this.removeButton.Visible; } set { this.removeButton.Visible = value; } } 该控件包含一个标准按钮控件。 此属性用于显示或隐藏按钮。 用户控件构建在单独的项目程序集中。 我把它放在一个表格上,我可以设置和取消设置上面的属性,一切似乎都工作得很好。 但是,当重建包含用户控件的项目时,属性值将翻转为“false”,这不是默认值。 在重建控件时,如何防止自定义属性丢失/更改其状态?

WPF自定义滑块由您自己绘制

这是我关于堆栈溢出的第一个问题,所以不要踢它)) 我在尝试创建Mac风格的滑块控件时遇到问题。 我找到了这个解决方案 ,我已经在我的解决方案中实现了它,但它仍然不能满足我,因为我需要一个更通用的解决方案。 基本上我需要在四张图片的帮助下创建这个滑块控件 – 轨道栏的右侧,左侧和中间(其余)图片以及一张拇指图片。 这些是PNG文件。 我可以设置默认的WPF滑块来支持这种面向资源的行为吗? 我真的很惊讶所有样本都包含样式模板,但没有人支持类似的东西 …. 任何人都能为我解决这个问题吗? 非常感谢你

在C#中同步闪烁标签

我创建了一个Forms.Label类,派生自Forms.Label ,它有一个Forms.Timer ,允许我启用和禁用闪烁效果。 我创建了4个BlinkingLabel类型的标签,我的问题是如果所有4个标签在不同时间闪烁,则闪烁效果不会同步。 如何以一种方式调整我的设计,即使标签在不同时间闪烁,闪烁也会同步? *******编辑******我添加了以下代码,但我仍然无法让标签1和2同时闪烁。 我要做的是测试以下内容:make label1闪烁然后我点击按钮使标签2闪烁并且它们不同步。 知道自己做错了什么吗? public partial class UserControl1 : UserControl { Timer blinkTimer; Color blinkingColor = Color.Red; int interval = 300; bool flag1 = false; bool flag2 = false; public UserControl1() { InitializeComponent(); // Blinking abel default values this.blinkTimer = new Timer(); this.blinkTimer.Interval = interval; ; this.blinkTimer.Tick += new System.EventHandler(timer_Tick); […]

WPF中的自定义控件在Winforms中是必要的吗?

在一次采访中,该公司询问我在WPF中使用自定义控件。 我发现了WPF创建控件(datatemplate,控件模板,样式,触发器等等)的所有function,必须编写一个覆盖OnRender方法的自定义控件,实际上并不是必需的。 后来发现他们的大部分开发都在Winforms中。 如果从100%WPF方向控制,是否有必要使用OnRender覆盖编写自定义控件? Winform方法实际上没有使用创建控件的WPF组合技术,它似乎不是基于WPF知识的问题。 谢谢哈罗德

在自定义控件上进行OneWayToSource / TwoWay绑定

我有一个带依赖项属性的自定义控件,定义如下: public class TemplatedTextBox : TextBox { public static readonly DependencyProperty SearchStringProperty = DependencyProperty.Register(“SearchString”, typeof(string), typeof(TemplatedTextBox), new UIPropertyMetadata(string.Empty)); public string SearchString { get { return (string)GetValue(SearchStringProperty); } set { SetValue(SearchStringProperty, value); } } } 我使用以下控件模板: 我想在OneWayToSource或TwoWay绑定模式下将SearchTextBox的Text属性绑定到我的SearchString属性。 我试过了: Text=”{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SearchString, Mode=OneWayToSource}” 哪个什么都不做。 Text=”{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SearchString, Mode=TwoWay}” 和 Text=”{TemplateBinding SearchString}” 当我以编程方式更改SearchString TextBox上的Text更改时,哪个方向可以正常工作,但不是另一种方式 我也尝试将SearchString作为常规属性,并在各种Mode使用RelativeSource绑定它,但它不起作用。 在常规的View-to-ViewModel绑定中,这是一个非常直接的事情,所以我在这里缺少什么?

自定义DataPager的问题

我试图将asp.net DataPager控件扩展为具有预定义模板的自定义控件。 这是所需的输出 问题 : 当我第一次加载包含自定义DataPager的页面时,我的ObjectDataSource的SelectMethod被调用了3次。 当我尝试使用DataPager加载另一页数据时,SelectMethod被调用两次。 当我尝试通过使用Next / Previous按钮或DropDownList加载另一页数据时,页面不会更改。 我运行了一些调试,发现它没有将正确的值传递给SelectMethod的StartRowIndexParameter(它每次调用方法时都传递0)。 这是我的自定义控件的代码。 public class DataPagerDDL : DataPager { protected override void RenderContents(HtmlTextWriter writer) { //add custom template TemplatePagerField templateField = new TemplatePagerField(); templateField.PagerTemplate = new CustomTemplate(); Fields.Add(templateField); //add previous/next page template NextPreviousPagerField nextPreviousField = new NextPreviousPagerField(); nextPreviousField.ShowFirstPageButton = false; nextPreviousField.ShowLastPageButton = false; nextPreviousField.PreviousPageText = “<>”; […]

如何制作一个有两个手柄(针)的SlideBar(TrackBar)

我的问题是我必须制作一个有两个手柄(针)的SlideBar(TrackBar) 1- Minmum(较低值)2-最大值(较高值) 喜欢: 开始结束实际上可能需要的范围是两个长约2000个刻度到滑动条上。 到目前为止,我已经在互联网上搜索过,我在代码项目中找到了一个Slidebar示例: http://www.codeproject.com/Articles/28717/A-custom-range-selector-control-in-C-with-a-little它可以选择我们从XML文件中添加范围值但是有两个长值它的范围值是重叠的,可以看到一条直线。因为我是C#的新手而且不知道开发自定义控件。 任何建议都会非常感激。

如何在datagridviewcell上绘制自定义控件?

我想为datagridviewcell托管一个自定义控件。 我唯一的好参考是http://msdn.microsoft.com/en-us/library/7tas5c80.aspx 但是,我希望单元格显示我自己的用户控件 public class CustomCell : DataGridViewTextBoxCell { protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } } 谁能指导我怎么做?

创建自定义RichTextBox控件

我相信我需要在C#中创建自定义RichTextBox 。 一种这样的: 我承认它甚至可能不必是RichTextBox ,但经过一些研究我认为这将是最简单的方法。 我需要的function是每行的图标,复选框和文本格式。 我的程序将处理文本的每一行,并标记正确,不正确的行,并删除在进一步工作中不需要的行,同时显示当前处理的行并允许用户自由编辑某些行(此处: 大约3 000之前的行)将不会被编辑,但那些在线下将是)。 那有什么问题呢? 我不知道如何完成它。 我已经看过如何在附近制作带有图标或复选框的单行textBox教程,但我不知道如何制作两者,并且对于多行textBox(所以我可以自由滚动,一切都会流畅地工作)。 我也读过关于SO的一些问题,但都没有帮助我。 我只是不知道如何开始,我意识到它不会是5分钟的工作,但我愿意这样做。 到目前为止,我只能创建源自RichTextBox自定义控件,但我不知道哪些方法以及如何覆盖。 任何帮助赞赏。

WPF自定义控件的ToolTip MultiBinding问题

当我在WPF自定义控件中设置工具提示绑定时,这种方式非常完美: public override void OnApplyTemplate() { base.OnApplyTemplate(); … SetBinding(ToolTipProperty, new Binding { Source = this, Path = new PropertyPath(“Property1”), StringFormat = “ValueOfProp1: {0}” }); } 但是当我尝试使用MultiBinding在ToolTip中有多个属性时,它不起作用: public override void OnApplyTemplate() { base.OnApplyTemplate(); … MultiBinding multiBinding = new MultiBinding(); multiBinding.StringFormat = “ValueOfProp1: {0}\nValueOfProp2: {1}\nValueOfProp3: {2}\n”; multiBinding.Bindings.Add(new Binding { Source = this, Path = new PropertyPath(“Property1”) }); […]