This will be another short post like Customs Fields at runtime for XAF. It is a really simple controller and sometimes I wonder when doing a post if the topic maybe it is too (for lack of a better word) simple, but I pat myself in the back because I truly believe that if it helps at least one person I am happy about it (It also helps me when I don’t remember what I did 6 months from now).
The task presented in this post was requested for one of our customers where for some reason they prefer all text inside their windows application exclusively in UPPERCASE.
Weirdly enough their requirement was not for labels, navigation items or actions (I believe they handled that trough localization). What they need was only input data.
As always I did a research trough the support tickets and got it working fairly quick.
public partial class WinUpperCaseController : ViewController { System.Collections.Generic.IList<StringPropertyEditor> _editor; public WinUpperCaseController() { InitializeComponent(); // Target required Views (via the TargetXXX properties) and create their Actions. } protected override void OnActivated() { base.OnActivated(); var detailView = View as DetailView; if (detailView != null) { _editor = detailView.GetItems<StringPropertyEditor>(); //as StringPropertyEditor; if (_editor != null) { foreach (var editor in _editor) { editor.ControlCreated += editor_ControlCreated; } } } // Perform various tasks depending on the target View. } void editor_ControlCreated(object sender, EventArgs e) { ((StringPropertyEditor)sender).Control.Properties.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; } protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); var listView = View as ListView; GridListEditor gridListEditor = listView?.Editor as GridListEditor; if (gridListEditor != null) { var gridControl = gridListEditor.Grid; RepositoryItemTextEdit editor = (RepositoryItemTextEdit)gridControl.RepositoryItems.Add("TextEdit"); editor.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; foreach (GridColumn col in gridListEditor.GridView.Columns) col.ColumnEdit = editor; } // Access and customize the target View control. } protected override void OnDeactivated() { // Unsubscribe from previously subscribed events and release other references and resources. base.OnDeactivated(); if (_editor != null) { foreach (var editor in _editor) { editor.ControlCreated -= editor_ControlCreated; } _editor = null; } } }
If you check the code above for DetailViews we subscribe to the ControlCreated event of the StringPropertyEditor and set the CharacterCasing as Upper and for ListViews we grab the RepositoryItemTextEdit of the GridControl and do the same.
See it in Action:
In case you are wondering: I don’t have CapsLock enabled 🤞 I promise.
Source Code: https://github.com/jjcolumb/UpperCaseXAF
Until next time, XAF out!