DynamicStatusBar.cs 28 KB

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