WPF: Setting Focus in a Custom User Control

When you create a custom user control, it typically contains child user interface elements. To provide a proper “Focus” experience at run time, you need to do the following: 1. Select your user control in design mode and check the Focusable check box 2. Create a handler method for your user control’s GotFocus event. In the event handler method, add a line of code that sets focus to the child control you want to initially receive focus. For example: private void AutoCompleteTextBox_GotFocus(object sender, RoutedEventArgs e){   this.txtTextBox.Focus();} Best Regards,Kevin McNeishINETA SpeakerChief Software Architect, MM .NET Application Frameworkwww.oakleafsd.com

Silverlight: Fixing the "Tag Expander Does Not Exist" Compiler Error

If you create a new Silverlight Navigation project, then compile immediately with no changes, you will get the following compiler error: The tag ‘Expander’ does not exist in XML namespace ‘clr-namespace:System.Windows.Controls;assenbly=System.Windows.Controls’ This is because the Expander element (as well as DockPanel, WrapPanel, HeaderedContentControl, Viewbox, and DataForm have been moved to the Silverlight Toolkit. To fix this problem: 1. If you haven’t already done so, download and install the Silverlight Toolkit (http://www.codeplex.com/Silverlight) 2. Add the System.Windows.Controls.Toolkit assembly to your project 3. Add the following namespace reference to the top of your project’s ErrorWindow.xaml file: xmlns:controlsToolkit=”clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit”4. 4. In the body of the … Continue reading Silverlight: Fixing the "Tag Expander Does Not Exist" Compiler Error

WPF: Setting the Height or Width to Auto in Code

At times, you may want to programmatically set the Height or Width of a WPF element to Auto in code. To do this, just use the Double.NaN (Not a Number) value. For example, in C#: this.txtName.Width = Double.NaN; And in VB .NET: Me.txtName.Width = Double.Nan Best Regards,Kevin McNeishINETA SpeakerChief Architect, MM .NET Application Frameworkwww.oakleafsd.com