user-controls

A 'Binding' can only be set on a DependencyProperty of a DependencyObject

跟風遠走 提交于 2019-12-28 05:36:16
问题 From a custom control based on TextBox , I created a property named Items , in this way: public class NewTextBox : TextBox { public ItemCollection Items { get; set; } } When using the custom control in XAML, I cannot bind the property because it raises exception "A 'Binding' can only be set on a DependencyProperty of a DependencyObject.". How do I solve this exception? 回答1: As a side note, it is also worth noting that you will get these binding errors if you copy and paste between objects and

How to troubleshoot and debug Visual Studio design mode errors?

流过昼夜 提交于 2019-12-28 02:05:17
问题 Using Windows 7 and Visual Studio 2010, I am writing a C# custom UserControl. I was coding in code view for weeks and recently when I tried to switch to design mode, Visual Studio hanged, "NOT RESPONDING". I can wait for an hour, and still nothing happens. Clicking on the close button it gives the "Do you want to wait, close, restart and send information to Microsoft" dialog. Is there a way to (stack)trace the code that the designer is trying to execute? Maybe design-time trace messages or

Can't use implemented namespace System.Windows

微笑、不失礼 提交于 2019-12-25 17:45:01
问题 I have a UserControl with a context menu, when the user clicks on an item in the context menu I want to let another user dialog pop up. I designed a user dialog and searched for a method to let it pop up. I found the easy variant with: Window myWindow = new Window { Title = "myTitle".. }; and then myWindow.ShowDialog(); Then I implemented the reference to System.Windows and used the line: using System.Windows; But when I try to write my Code above Visual studio says type or namespace not

WPF TreeView Selected Item and showing User Controls

前提是你 提交于 2019-12-25 16:57:48
问题 I'm getting myself all in a pickle with TreeViews and User Controls; I'm fairly new to WPF so apologies in advance. Synopsis I have a collection of VM classes for my TreeView Items. So the TreeView is bound to a collection of [Parent] VM instances, each of which has a collection of [Child]ren, and each [Child] has other data and other collections (which I won't bore you with). The TreeView is on the left side of the form, and on the right I have a user control which should only be visible

How to dynamically add user controls within a user control

荒凉一梦 提交于 2019-12-25 16:49:46
问题 I want to create a user control that will again contain a user control that will be dynamically generated and can be repeated N times with respect to data present in data table. How can i do this. 回答1: You want to use TemplateControl.LoadControl (which both Page, UserControl and MasterPage inherit from). You need to do this during the Init event for postback stuff to work. void Page_Init(Object Sender, EventArgs e) { var control = LoadControl("Awesome.ascx"); // ... Magic! } 回答2: Place a

Why don't my user controls render?

若如初见. 提交于 2019-12-25 12:40:14
问题 I've created a set of user controls in vb.net and in their original project they work fine. I've since created a user control library dll and I wish to use it in a new project. I add the reference to the dll fine, specify the tag library in an asp.net page fine and define controls on the page fine. Everything seems to work except I get no rendered output. Various properies of the controls and the page_load methods are all called. Asp.net trace shows the controls in the page hierarchy etc Just

Set selected index in a Dropdownlist in usercontrol

大城市里の小女人 提交于 2019-12-25 11:57:15
问题 I'm fairly new to usercontrols. So far, I've found them quite useful for handling large amounts of repeating user input fields. However, I'm having a problem with prepopulating a dropdownlist in the control. I add a ddl to my ascx page then I bind the ddl and expose it: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<Travel_CarSize> tc = Travel_CarSizes.GetCarSizes(); ddlCarSize.DataSource = tc; ddlCarSize.DataTextField = "CarSize"; ddlCarSize.DataValueField =

Replace a string with a user control

允我心安 提交于 2019-12-25 10:35:24
问题 How can I replace a string with UserControl? if string = [$control1$] replace with control1.ascx 回答1: You can't set a string to a control, as they are completely different types. You can set a string to the text of a control, as the text is of type string: string myString = control.Text; 回答2: Do you mean the HTML output by the user control if it is loaded into a page? Try this: using System.Web.UI; public static string RenderToString(this Control control) { var sb = new StringBuilder(); using

C# How to change the value of a textbox on a UserControl on another Form

倖福魔咒の 提交于 2019-12-25 09:27:52
问题 How would I be able to change the value of a textbox which is inside another form's usercontrol from another Form. Code on UserControl2 of Form1: public string TextValue { get { return textBox2.Text; } set { textBox2.Text = value; } } Code on Form2 private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedIndices.Count <= 0) { return; } int intselectedindex = listView1.SelectedIndices[0]; if (intselectedindex >= 0) { u1.TextValue = listView1.Items

ASP.NET Usercontrol Property value does not run <%= markup

吃可爱长大的小学妹 提交于 2019-12-25 08:57:48
问题 Well i have a usercontrol with a property "ClientScript" and in the aspx file where i use the usercontrol i set the value to =document.getElementsByName('<%=ReportViewer1.ClientId %>$ctl01$ctl07$ctl00$ctl00$ctl00')[0].click(); return false; the problem here is that the is litterly passed to the property and not parsed first and replaced by the ClientID.. I had the same clientscript applied to a buttons OnClientClick and there it worked... Must i apply some sort of attribute to the property to