SilverlightShow: Create a Custom Control - Inheriting from TextBox Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) RE: Create a Custom Control - Inheriting from TextBox <p>Hi Devendra, good on you for getting your hands dirty with a bit of GUI development!</p> <p>You can find the source code <a href="http://www.silverlightshow.net/Storage/Sources/CustomControlDemo.zip">here</a>. That should show you where to put the XAML from the various steps.</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment5701 PhilM http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Tue, 15 Mar 2011 04:37:41 GMT RE: Create a Custom Control - Inheriting from TextBox <p>Hi, </p> <p>This is a good article. But i didnt understand few things in it. in the article above, where it says "Step 5 – Add Custom Elements" and then textblock and a button, where do you add that?<br /> Do you have a source code for this article? So i can check where exactly codes are written and in which files. If not then no problemo. <br /> <br /> I am just creating a test app, but i could not figure out where to write the parts from Step 5 and 2 of the boxes from Step 6.<br /> <br /> I am sorry if you think my questions are a little stupid, but i am a database guy and i am making my own website in silverlight by reading and learning from internet.</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment5699 Devendra C. http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Tue, 15 Mar 2011 03:16:35 GMT RE: Create a Custom Control - Inheriting from TextBox <p>LG, if you want to have the BorderWidth and BorderHeight map directly to the Width and Height then I would recommend dropping the BorderWidth and BorderHeight properties all-together. The <a href="http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement(v=vs.95).aspx" target="_blank">FrameworkElement</a> class comes with all the width and height properties you need and you may just be complicating things by trying to add more (unless they function quite differently).</p> <p>If you removed your two properties then you could just set the Border alignment to stretch both vertically and horizontally and let the FrameworkElement base class manage the dimensions of the control for you.</p> <p>If the Border really does behave differently then you would have to use code to respond to changes in the BorderWidth and BorderHeight properties (you register a handler when you register the dependency properties). The handler could then adjust the Width and Height properties to suit.</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment5465 PhilM http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Wed, 09 Feb 2011 21:16:19 GMT RE: Create a Custom Control - Inheriting from TextBox <p>Thanks for the quick reply Phil. Great tutorial btw!</p> <p>I've got one more question. Assume that in the ResourceDictionary of the Custom Control I have only one Border. The width and height of the border are bound to the BorderWidth and BorderHeight properties as you describe it in your article. Now when I go into my main application and add the custom control I do something like this:</p> <p><controls:MyBorder BorderWidth="100" BorderHeight="100" /></p> <p>...and the binding works, and I get a Border 100x100. But the Width and Height of the control still hasn't changed.<br /> My question would be how would you go if you also wanted to resize the Width and Height to be the same as that of the Border? Is there anyway you can overwrite Width/Height or even better, bind them to BorderWidth/BorderHeight?</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment5461 LG http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Wed, 09 Feb 2011 16:26:05 GMT RE: Create a Custom Control - Inheriting from TextBox <p>LG, to do so you would just need to create a new project to contain it. You can follow <a href="http://www.silverlightshow.net/items/Creating-a-Skinnable-Custom-Control-in-Silverlight-3-Part-I.aspx" target="_blank">this tutorial</a> for the steps to do that.</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment5458 PhilM http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Tue, 08 Feb 2011 23:07:17 GMT RE: Create a Custom Control - Inheriting from TextBox <p>Is there anyway you could compile this into a DLL so that other projects could use it?</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment5457 LG http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Tue, 08 Feb 2011 23:01:18 GMT RE: Create a Custom Control - Inheriting from TextBox <p>GreenLion, the purpose of that part of the tutorial is to end up with some nice animations in the default control template. It is much easier to create XAML for animations in Blend than doing it by hand. So I build the control without the animations and use Blend to create a new control template for it- a copy of the existing one - and add the animations.</p> <p>Now I have the XAML for the control with animations so I copy that back into the default.xaml for the control and it becomes the <em>new</em> default control template. Sorry if the article was unclear on this.</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment4477 PhilM http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Wed, 15 Sep 2010 22:26:31 GMT RE: Create a Custom Control - Inheriting from TextBox <p>The Part with the XAML copying is confusing.</p> <p>Could you explain why we have to do this? i dont get it... </p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment4453 GreenLion http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Mon, 13 Sep 2010 15:16:11 GMT RE: Create a Custom Control - Inheriting from TextBox <p>Great tip Richard, thanks!</p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment4310 PhilM http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Sun, 22 Aug 2010 22:34:27 GMT RE: Create a Custom Control - Inheriting from TextBox <p>This example also works for WPF with a minor change. Change the name of the scrollviewer to "<span style="font-family: consolas; color: #0000ff; font-size: 13px;">PART_ContentHost".</span></p> <p><span style="font-family: consolas; color: #0000ff; font-size: 13px;">Great example! <p> </p> </span></p> <p> </p> http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx#comment4273 RIchard B. http://www.silverlightshow.net/items/Create-a-Custom-Control-Inheriting-from-TextBox.aspx Fri, 20 Aug 2010 17:09:13 GMT