DynamicStatusBar.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. using System.Text;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Reflection;
  7. using System.Runtime.CompilerServices;
  8. using Terminal.Gui;
  9. namespace UICatalog.Scenarios {
  10. [ScenarioMetadata (Name: "Dynamic StatusBar", Description: "Demonstrates how to add and remove a StatusBar and change items dynamically.")]
  11. [ScenarioCategory ("Top Level Windows")]
  12. public class DynamicStatusBar : Scenario {
  13. public override void Init ()
  14. {
  15. Application.Init ();
  16. Application.Top.Add (new DynamicStatusBarSample () { Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}" });
  17. }
  18. public class DynamicStatusItemList {
  19. public string Title { get; set; }
  20. public StatusItem StatusItem { get; set; }
  21. public DynamicStatusItemList () { }
  22. public DynamicStatusItemList (string title, StatusItem statusItem)
  23. {
  24. Title = title;
  25. StatusItem = statusItem;
  26. }
  27. public override string ToString () => $"{Title}, {StatusItem}";
  28. }
  29. public class DynamicStatusItem {
  30. public string title = "New";
  31. public string action = "";
  32. public string shortcut;
  33. public DynamicStatusItem () { }
  34. public DynamicStatusItem (string title)
  35. {
  36. this.title = title;
  37. }
  38. public DynamicStatusItem (string title, string action, string shortcut = null)
  39. {
  40. this.title = title;
  41. this.action = action;
  42. this.shortcut = shortcut;
  43. }
  44. }
  45. public class DynamicStatusBarSample : Window {
  46. StatusBar _statusBar;
  47. StatusItem _currentStatusItem;
  48. int _currentSelectedStatusBar = -1;
  49. StatusItem _currentEditStatusItem;
  50. ListView _lstItems;
  51. public DynamicStatusItemModel DataContext { get; set; }
  52. public DynamicStatusBarSample () : base ()
  53. {
  54. DataContext = new DynamicStatusItemModel ();
  55. var _frmDelimiter = new FrameView ("Shortcut Delimiter:") {
  56. X = Pos.Center (),
  57. Y = 0,
  58. Width = 25,
  59. Height = 4
  60. };
  61. var _txtDelimiter = new TextField (StatusBar.ShortcutDelimiter) {
  62. X = Pos.Center (),
  63. Width = 2,
  64. };
  65. _txtDelimiter.TextChanged += (s, _) => StatusBar.ShortcutDelimiter = _txtDelimiter.Text;
  66. _frmDelimiter.Add (_txtDelimiter);
  67. Add (_frmDelimiter);
  68. var _frmStatusBar = new FrameView ("Items:") {
  69. Y = 5,
  70. Width = Dim.Percent (50),
  71. Height = Dim.Fill (2)
  72. };
  73. var _btnAddStatusBar = new Button ("Add a StatusBar") {
  74. Y = 1,
  75. };
  76. _frmStatusBar.Add (_btnAddStatusBar);
  77. var _btnRemoveStatusBar = new Button ("Remove a StatusBar") {
  78. Y = 1
  79. };
  80. _btnRemoveStatusBar.X = Pos.AnchorEnd () - (Pos.Right (_btnRemoveStatusBar) - Pos.Left (_btnRemoveStatusBar));
  81. _frmStatusBar.Add (_btnRemoveStatusBar);
  82. var _btnAdd = new Button (" Add ") {
  83. Y = Pos.Top (_btnRemoveStatusBar) + 2,
  84. };
  85. _btnAdd.X = Pos.AnchorEnd () - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
  86. _frmStatusBar.Add (_btnAdd);
  87. _lstItems = new ListView (new List<DynamicStatusItemList> ()) {
  88. ColorScheme = Colors.Dialog,
  89. Y = Pos.Top (_btnAddStatusBar) + 2,
  90. Width = Dim.Fill () - Dim.Width (_btnAdd) - 1,
  91. Height = Dim.Fill (),
  92. };
  93. _frmStatusBar.Add (_lstItems);
  94. var _btnRemove = new Button ("Remove") {
  95. X = Pos.Left (_btnAdd),
  96. Y = Pos.Top (_btnAdd) + 1
  97. };
  98. _frmStatusBar.Add (_btnRemove);
  99. var _btnUp = new Button ("^") {
  100. X = Pos.Right (_lstItems) + 2,
  101. Y = Pos.Top (_btnRemove) + 2
  102. };
  103. _frmStatusBar.Add (_btnUp);
  104. var _btnDown = new Button ("v") {
  105. X = Pos.Right (_lstItems) + 2,
  106. Y = Pos.Top (_btnUp) + 1
  107. };
  108. _frmStatusBar.Add (_btnDown);
  109. Add (_frmStatusBar);
  110. var _frmStatusBarDetails = new DynamicStatusBarDetails ("StatusBar Item Details:") {
  111. X = Pos.Right (_frmStatusBar),
  112. Y = Pos.Top (_frmStatusBar),
  113. Width = Dim.Fill (),
  114. Height = Dim.Fill (4)
  115. };
  116. Add (_frmStatusBarDetails);
  117. _btnUp.Clicked += (s,e) => {
  118. var i = _lstItems.SelectedItem;
  119. var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null;
  120. if (statusItem != null) {
  121. var items = _statusBar.Items;
  122. if (i > 0) {
  123. items [i] = items [i - 1];
  124. items [i - 1] = statusItem;
  125. DataContext.Items [i] = DataContext.Items [i - 1];
  126. DataContext.Items [i - 1] = new DynamicStatusItemList (statusItem.Title, statusItem);
  127. _lstItems.SelectedItem = i - 1;
  128. _statusBar.SetNeedsDisplay ();
  129. }
  130. }
  131. };
  132. _btnDown.Clicked += (s,e) => {
  133. var i = _lstItems.SelectedItem;
  134. var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [i].StatusItem : null;
  135. if (statusItem != null) {
  136. var items = _statusBar.Items;
  137. if (i < items.Length - 1) {
  138. items [i] = items [i + 1];
  139. items [i + 1] = statusItem;
  140. DataContext.Items [i] = DataContext.Items [i + 1];
  141. DataContext.Items [i + 1] = new DynamicStatusItemList (statusItem.Title, statusItem);
  142. _lstItems.SelectedItem = i + 1;
  143. _statusBar.SetNeedsDisplay ();
  144. }
  145. }
  146. };
  147. var _btnOk = new Button ("Ok") {
  148. X = Pos.Right (_frmStatusBar) + 20,
  149. Y = Pos.Bottom (_frmStatusBarDetails),
  150. };
  151. Add (_btnOk);
  152. var _btnCancel = new Button ("Cancel") {
  153. X = Pos.Right (_btnOk) + 3,
  154. Y = Pos.Top (_btnOk),
  155. };
  156. _btnCancel.Clicked += (s,e) => {
  157. SetFrameDetails (_currentEditStatusItem);
  158. };
  159. Add (_btnCancel);
  160. _lstItems.SelectedItemChanged += (s, e) => {
  161. SetFrameDetails ();
  162. };
  163. _btnOk.Clicked += (s,e) => {
  164. if (string.IsNullOrEmpty (_frmStatusBarDetails._txtTitle.Text) && _currentEditStatusItem != null) {
  165. MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok");
  166. } else if (_currentEditStatusItem != null) {
  167. _frmStatusBarDetails._txtTitle.Text = SetTitleText (
  168. _frmStatusBarDetails._txtTitle.Text, _frmStatusBarDetails._txtShortcut.Text);
  169. var statusItem = new DynamicStatusItem (_frmStatusBarDetails._txtTitle.Text,
  170. _frmStatusBarDetails._txtAction.Text,
  171. _frmStatusBarDetails._txtShortcut.Text);
  172. UpdateStatusItem (_currentEditStatusItem, statusItem, _lstItems.SelectedItem);
  173. }
  174. };
  175. _btnAdd.Clicked += (s,e) => {
  176. if (StatusBar == null) {
  177. MessageBox.ErrorQuery ("StatusBar Bar Error", "Must add a StatusBar first!", "Ok");
  178. _btnAddStatusBar.SetFocus ();
  179. return;
  180. }
  181. var frameDetails = new DynamicStatusBarDetails ();
  182. var item = frameDetails.EnterStatusItem ();
  183. if (item == null) {
  184. return;
  185. }
  186. StatusItem newStatusItem = CreateNewStatusBar (item);
  187. _currentSelectedStatusBar++;
  188. _statusBar.AddItemAt (_currentSelectedStatusBar, newStatusItem);
  189. DataContext.Items.Add (new DynamicStatusItemList (newStatusItem.Title, newStatusItem));
  190. _lstItems.MoveDown ();
  191. SetFrameDetails ();
  192. };
  193. _btnRemove.Clicked += (s,e) => {
  194. var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null;
  195. if (statusItem != null) {
  196. _statusBar.RemoveItem (_currentSelectedStatusBar);
  197. DataContext.Items.RemoveAt (_lstItems.SelectedItem);
  198. if (_lstItems.Source.Count > 0 && _lstItems.SelectedItem > _lstItems.Source.Count - 1) {
  199. _lstItems.SelectedItem = _lstItems.Source.Count - 1;
  200. }
  201. _lstItems.SetNeedsDisplay ();
  202. SetFrameDetails ();
  203. }
  204. };
  205. _lstItems.Enter += (s, e) => {
  206. var statusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null;
  207. SetFrameDetails (statusItem);
  208. };
  209. _btnAddStatusBar.Clicked += (s,e) => {
  210. if (_statusBar != null) {
  211. return;
  212. }
  213. _statusBar = new StatusBar ();
  214. Add (_statusBar);
  215. };
  216. _btnRemoveStatusBar.Clicked += (s,e) => {
  217. if (_statusBar == null) {
  218. return;
  219. }
  220. Remove (_statusBar);
  221. _statusBar = null;
  222. DataContext.Items = new List<DynamicStatusItemList> ();
  223. _currentStatusItem = null;
  224. _currentSelectedStatusBar = -1;
  225. SetListViewSource (_currentStatusItem, true);
  226. SetFrameDetails (null);
  227. };
  228. SetFrameDetails ();
  229. var ustringConverter = new UStringValueConverter ();
  230. var listWrapperConverter = new ListWrapperConverter ();
  231. var lstItems = new Binding (this, "Items", _lstItems, "Source", listWrapperConverter);
  232. void SetFrameDetails (StatusItem statusItem = null)
  233. {
  234. StatusItem newStatusItem;
  235. if (statusItem == null) {
  236. newStatusItem = DataContext.Items.Count > 0 ? DataContext.Items [_lstItems.SelectedItem].StatusItem : null;
  237. } else {
  238. newStatusItem = statusItem;
  239. }
  240. _currentEditStatusItem = newStatusItem;
  241. _frmStatusBarDetails.EditStatusItem (newStatusItem);
  242. var f = _btnOk.Enabled == _frmStatusBarDetails.Enabled;
  243. if (!f) {
  244. _btnOk.Enabled = _frmStatusBarDetails.Enabled;
  245. _btnCancel.Enabled = _frmStatusBarDetails.Enabled;
  246. }
  247. }
  248. void SetListViewSource (StatusItem _currentStatusItem, bool fill = false)
  249. {
  250. DataContext.Items = new List<DynamicStatusItemList> ();
  251. var statusItem = _currentStatusItem;
  252. if (!fill) {
  253. return;
  254. }
  255. if (statusItem != null) {
  256. foreach (var si in _statusBar.Items) {
  257. DataContext.Items.Add (new DynamicStatusItemList (si.Title, si));
  258. }
  259. }
  260. }
  261. StatusItem CreateNewStatusBar (DynamicStatusItem item)
  262. {
  263. var newStatusItem = new StatusItem (ShortcutHelper.GetShortcutFromTag (
  264. item.shortcut, StatusBar.ShortcutDelimiter),
  265. item.title, _frmStatusBarDetails.CreateAction (item));
  266. return newStatusItem;
  267. }
  268. void UpdateStatusItem (StatusItem _currentEditStatusItem, DynamicStatusItem statusItem, int index)
  269. {
  270. _currentEditStatusItem = CreateNewStatusBar (statusItem);
  271. _statusBar.Items [index] = _currentEditStatusItem;
  272. if (DataContext.Items.Count == 0) {
  273. DataContext.Items.Add (new DynamicStatusItemList (_currentEditStatusItem.Title, _currentEditStatusItem));
  274. }
  275. DataContext.Items [index] = new DynamicStatusItemList (_currentEditStatusItem.Title, _currentEditStatusItem);
  276. SetFrameDetails (_currentEditStatusItem);
  277. }
  278. //_frmStatusBarDetails.Initialized += (s, e) => _frmStatusBarDetails.Enabled = false;
  279. }
  280. public static string SetTitleText (string title, string shortcut)
  281. {
  282. var txt = title;
  283. var split = title.Split ('~');
  284. if (split.Length > 1) {
  285. txt = split [2].Trim (); ;
  286. }
  287. if (string.IsNullOrEmpty (shortcut)) {
  288. return txt;
  289. }
  290. return $"~{shortcut}~ {txt}";
  291. }
  292. }
  293. public class DynamicStatusBarDetails : FrameView {
  294. public StatusItem _statusItem;
  295. public TextField _txtTitle;
  296. public TextView _txtAction;
  297. public TextField _txtShortcut;
  298. public DynamicStatusBarDetails (StatusItem statusItem = null) : this (statusItem == null ? "Adding New StatusBar Item." : "Editing StatusBar Item.")
  299. {
  300. _statusItem = statusItem;
  301. }
  302. public DynamicStatusBarDetails (string title) : base (title)
  303. {
  304. var _lblTitle = new Label ("Title:") {
  305. Y = 1
  306. };
  307. Add (_lblTitle);
  308. _txtTitle = new TextField () {
  309. X = Pos.Right (_lblTitle) + 4,
  310. Y = Pos.Top (_lblTitle),
  311. Width = Dim.Fill ()
  312. };
  313. Add (_txtTitle);
  314. var _lblAction = new Label ("Action:") {
  315. X = Pos.Left (_lblTitle),
  316. Y = Pos.Bottom (_lblTitle) + 1
  317. };
  318. Add (_lblAction);
  319. _txtAction = new TextView () {
  320. X = Pos.Left (_txtTitle),
  321. Y = Pos.Top (_lblAction),
  322. Width = Dim.Fill (),
  323. Height = 5
  324. };
  325. Add (_txtAction);
  326. var _lblShortcut = new Label ("Shortcut:") {
  327. X = Pos.Left (_lblTitle),
  328. Y = Pos.Bottom (_txtAction) + 1
  329. };
  330. Add (_lblShortcut);
  331. _txtShortcut = new TextField () {
  332. X = Pos.X (_txtAction),
  333. Y = Pos.Y (_lblShortcut),
  334. Width = Dim.Fill (),
  335. ReadOnly = true
  336. };
  337. _txtShortcut.KeyDown += (s, e) => {
  338. if (!ProcessKey (e.KeyEvent)) {
  339. return;
  340. }
  341. var k = ShortcutHelper.GetModifiersKey (e.KeyEvent);
  342. if (CheckShortcut (k, true)) {
  343. e.Handled = true;
  344. }
  345. };
  346. bool ProcessKey (KeyEvent ev)
  347. {
  348. switch (ev.Key) {
  349. case Key.CursorUp:
  350. case Key.CursorDown:
  351. case Key.Tab:
  352. case Key.BackTab:
  353. return false;
  354. }
  355. return true;
  356. }
  357. bool CheckShortcut (Key k, bool pre)
  358. {
  359. var m = _statusItem != null ? _statusItem : new StatusItem (k, "", null);
  360. if (pre && !ShortcutHelper.PreShortcutValidation (k)) {
  361. _txtShortcut.Text = "";
  362. return false;
  363. }
  364. if (!pre) {
  365. if (!ShortcutHelper.PostShortcutValidation (ShortcutHelper.GetShortcutFromTag (
  366. _txtShortcut.Text, StatusBar.ShortcutDelimiter))) {
  367. _txtShortcut.Text = "";
  368. return false;
  369. }
  370. return true;
  371. }
  372. _txtShortcut.Text = ShortcutHelper.GetShortcutTag (k, StatusBar.ShortcutDelimiter);
  373. return true;
  374. }
  375. _txtShortcut.KeyUp += (s, e) => {
  376. var k = ShortcutHelper.GetModifiersKey (e.KeyEvent);
  377. if (CheckShortcut (k, false)) {
  378. e.Handled = true;
  379. }
  380. };
  381. Add (_txtShortcut);
  382. var _btnShortcut = new Button ("Clear Shortcut") {
  383. X = Pos.X (_lblShortcut),
  384. Y = Pos.Bottom (_txtShortcut) + 1
  385. };
  386. _btnShortcut.Clicked += (s,e) => {
  387. _txtShortcut.Text = "";
  388. };
  389. Add (_btnShortcut);
  390. }
  391. public DynamicStatusItem EnterStatusItem ()
  392. {
  393. var valid = false;
  394. if (_statusItem == null) {
  395. var m = new DynamicStatusItem ();
  396. _txtTitle.Text = m.title;
  397. _txtAction.Text = m.action;
  398. } else {
  399. EditStatusItem (_statusItem);
  400. }
  401. var _btnOk = new Button ("Ok") {
  402. IsDefault = true,
  403. };
  404. _btnOk.Clicked += (s,e) => {
  405. if (string.IsNullOrEmpty (_txtTitle.Text)) {
  406. MessageBox.ErrorQuery ("Invalid title", "Must enter a valid title!.", "Ok");
  407. } else {
  408. if (!string.IsNullOrEmpty (_txtShortcut.Text)) {
  409. _txtTitle.Text = DynamicStatusBarSample.SetTitleText (
  410. _txtTitle.Text, _txtShortcut.Text);
  411. }
  412. valid = true;
  413. Application.RequestStop ();
  414. }
  415. };
  416. var _btnCancel = new Button ("Cancel");
  417. _btnCancel.Clicked += (s,e) => {
  418. _txtTitle.Text = string.Empty;
  419. Application.RequestStop ();
  420. };
  421. var _dialog = new Dialog (_btnOk, _btnCancel) { Title = "Enter the menu details." };
  422. Width = Dim.Fill ();
  423. Height = Dim.Fill () - 1;
  424. _dialog.Add (this);
  425. _txtTitle.SetFocus ();
  426. _txtTitle.CursorPosition = _txtTitle.Text.Length;
  427. Application.Run (_dialog);
  428. if (valid) {
  429. return new DynamicStatusItem (_txtTitle.Text, _txtAction.Text, _txtShortcut.Text);
  430. } else {
  431. return null;
  432. }
  433. }
  434. public void EditStatusItem (StatusItem statusItem)
  435. {
  436. if (statusItem == null) {
  437. Enabled = false;
  438. CleanEditStatusItem ();
  439. return;
  440. } else {
  441. Enabled = true;
  442. }
  443. _statusItem = statusItem;
  444. _txtTitle.Text = statusItem?.Title ?? "";
  445. _txtAction.Text = statusItem != null && statusItem.Action != null ? GetTargetAction (statusItem.Action) : string.Empty;
  446. _txtShortcut.Text = ShortcutHelper.GetShortcutTag (statusItem.Shortcut, StatusBar.ShortcutDelimiter) ?? "";
  447. }
  448. void CleanEditStatusItem ()
  449. {
  450. _txtTitle.Text = "";
  451. _txtAction.Text = "";
  452. _txtShortcut.Text = "";
  453. }
  454. string GetTargetAction (Action action)
  455. {
  456. var me = action.Target;
  457. if (me == null) {
  458. throw new ArgumentException ();
  459. }
  460. object v = new object ();
  461. foreach (var field in me.GetType ().GetFields ()) {
  462. if (field.Name == "item") {
  463. v = field.GetValue (me);
  464. }
  465. }
  466. return v == null || !(v is DynamicStatusItem item) ? string.Empty : item.action;
  467. }
  468. public Action CreateAction (DynamicStatusItem item)
  469. {
  470. return new Action (() => MessageBox.ErrorQuery (item.title, item.action, "Ok"));
  471. }
  472. }
  473. public class DynamicStatusItemModel : INotifyPropertyChanged {
  474. public event PropertyChangedEventHandler PropertyChanged;
  475. private string statusBar;
  476. private List<DynamicStatusItemList> items;
  477. public string StatusBar {
  478. get => statusBar;
  479. set {
  480. if (value != statusBar) {
  481. statusBar = value;
  482. PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (GetPropertyName ()));
  483. }
  484. }
  485. }
  486. public List<DynamicStatusItemList> Items {
  487. get => items;
  488. set {
  489. if (value != items) {
  490. items = value;
  491. PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (GetPropertyName ()));
  492. }
  493. }
  494. }
  495. public DynamicStatusItemModel ()
  496. {
  497. Items = new List<DynamicStatusItemList> ();
  498. }
  499. public string GetPropertyName ([CallerMemberName] string propertyName = null)
  500. {
  501. return propertyName;
  502. }
  503. }
  504. public interface IValueConverter {
  505. object Convert (object value, object parameter = null);
  506. }
  507. public class Binding {
  508. public View Target { get; private set; }
  509. public View Source { get; private set; }
  510. public string SourcePropertyName { get; private set; }
  511. public string TargetPropertyName { get; private set; }
  512. private object sourceDataContext;
  513. private PropertyInfo sourceBindingProperty;
  514. private IValueConverter valueConverter;
  515. public Binding (View source, string sourcePropertyName, View target, string targetPropertyName, IValueConverter valueConverter = null)
  516. {
  517. Target = target;
  518. Source = source;
  519. SourcePropertyName = sourcePropertyName;
  520. TargetPropertyName = targetPropertyName;
  521. sourceDataContext = Source.GetType ().GetProperty ("DataContext").GetValue (Source);
  522. sourceBindingProperty = sourceDataContext.GetType ().GetProperty (SourcePropertyName);
  523. this.valueConverter = valueConverter;
  524. UpdateTarget ();
  525. var notifier = ((INotifyPropertyChanged)sourceDataContext);
  526. if (notifier != null) {
  527. notifier.PropertyChanged += (s, e) => {
  528. if (e.PropertyName == SourcePropertyName) {
  529. UpdateTarget ();
  530. }
  531. };
  532. }
  533. }
  534. private void UpdateTarget ()
  535. {
  536. try {
  537. var sourceValue = sourceBindingProperty.GetValue (sourceDataContext);
  538. if (sourceValue == null) {
  539. return;
  540. }
  541. var finalValue = valueConverter?.Convert (sourceValue) ?? sourceValue;
  542. var targetProperty = Target.GetType ().GetProperty (TargetPropertyName);
  543. targetProperty.SetValue (Target, finalValue);
  544. } catch (Exception ex) {
  545. MessageBox.ErrorQuery ("Binding Error", $"Binding failed: {ex}.", "Ok");
  546. }
  547. }
  548. }
  549. public class ListWrapperConverter : IValueConverter {
  550. public object Convert (object value, object parameter = null)
  551. {
  552. return new ListWrapper ((IList)value);
  553. }
  554. }
  555. public class UStringValueConverter : IValueConverter {
  556. public object Convert (object value, object parameter = null)
  557. {
  558. var data = Encoding.ASCII.GetBytes (value.ToString ());
  559. return StringExtensions.ToString (data);
  560. }
  561. }
  562. }
  563. }