How to Stretch WPF Tab Item Headers to Parent Control Width

I took Jordan’s example and made some changes to it. This version should work for any number of tabs: namespace WpfApplication1.Converters { public class TabSizeConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { TabControl tabControl = values[0] as TabControl; double width = tabControl.ActualWidth / tabControl.Items.Count; //Subtract 1, otherwise we … Read more

What is Dependency Injection and Inversion of Control in Spring Framework?

Spring helps in the creation of loosely coupled applications because of Dependency Injection. In Spring, objects define their associations (dependencies) and do not worry about how they will get those dependencies. It is the responsibility of Spring to provide the required dependencies for creating objects. For example: Suppose we have an object Employee and it … Read more

What is the best way to clear all controls on a form C#?

What I have come up with so far is something like this: public static class extenstions { private static Dictionary<Type, Action<Control>> controldefaults = new Dictionary<Type, Action<Control>>() { {typeof(TextBox), c => ((TextBox)c).Clear()}, {typeof(CheckBox), c => ((CheckBox)c).Checked = false}, {typeof(ListBox), c => ((ListBox)c).Items.Clear()}, {typeof(RadioButton), c => ((RadioButton)c).Checked = false}, {typeof(GroupBox), c => ((GroupBox)c).Controls.ClearControls()}, {typeof(Panel), c => ((Panel)c).Controls.ClearControls()} … Read more

How to change disabled background color of TextBox in WPF

Unfortunately for the TextBox control, it appears like it’s not as simple as just adding a trigger and changing the Background color when the trigger condition is true. You have to override the entire ControlTemplate to achieve this. Below is one example on how you might do this: <Window x:Class=”StackOverflow.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” Title=”MainWindow” Height=”350″ Width=”525″> … Read more

Pass click event of child control to the parent control

While you can interact with parent form directly from child like this.ParentForm.Close(), but it’s better to raise some events by child control and subscribe for the events in parent form. Raise event from Child: public event EventHandler CloseButtonClicked; protected virtual void OnCloseButtonClicked(EventArgs e) { CloseButtonClicked?.Invoke(this, e); } private void CloseButton_Click(object sender, EventArgs e) { OnCloseButtonClicked(e); … Read more

Applying Styles To ListItems in CheckBoxList

You can add Attributes to ListItems programmatically as follows. Say you’ve got a CheckBoxList and you are adding ListItems. You can add Attributes along the way. ListItem li = new ListItem(“Richard Byrd”, “11”); li.Selected = false; li.Attributes.Add(“Style”, “color: red;”); CheckBoxList1.Items.Add(li); This will make the color of the listitem text red. Experiment and have fun.