wpf custom button best approach

Like you, when I was getting started and wanted to understand how / what was going on and working with templates, it took a lot of trial and error. Hopefully my research and some step-by-step components can help you customize to your liking and KNOWING where things are coming from. First, when trying to understand … Read more

MVVM – what is the ideal way for usercontrols to talk to each other

Typically, it’s best to try to reduce the amount of communication between parts, as each time two user controls “talk” to each other, you’re introducing a dependency between them. That being said, there are a couple of things to consider: UserControls can always “talk” to their containing control via exposing properties and using DataBinding. This … Read more

Setting DataContext within UserControl is affecting bindings in parent

The declaration of your control and the instantiation are basically manipulating the same object, all the properties that are set in the declaration are also set on every instance. So if the properties were “visible” so to speak: <UserControl x:Class=”MyControlLib.ParentControl” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ xmlns:ctrl=”clr-namespace:MyControlLib”> <ctrl:ChildControl x:Name=”ChildName” DataContext=”{Binding RelativeSource={RelativeSource Self}}” PropertyOnChild=”{Binding PropertyInParentContext}”/> </UserControl> This is why … Read more

Document.Ready() is not working after PostBack

This will be a problem with partial postback. The DOM isn’t reloaded and so the document ready function won’t be hit again. You need to assign a partial postback handler in JavaScript like so… function doSomething() { //whatever you want to do on partial postback } Sys.WebForms.PageRequestManager.getInstance().add_endRequest(doSomething); The above call to add_endRequest should be placed … Read more

How do I raise an event in a usercontrol and catch it in mainpage?

Check out Event Bubbling — http://msdn.microsoft.com/en-us/library/aa719644%28vs.71%29.aspx Example: User Control public event EventHandler StatusUpdated; private void FunctionThatRaisesEvent() { //Null check makes sure the main page is attached to the event if (this.StatusUpdated != null) this.StatusUpdated(this, new EventArgs()); } Main Page/Form public void MyApp() { //USERCONTROL = your control with the StatusUpdated event this.USERCONTROL.StatusUpdated += new EventHandler(MyEventHandlerFunction_StatusUpdated); … Read more