KeyboardNavigationTests_Tab.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using Avalonia.Controls;
  4. using Xunit;
  5. namespace Avalonia.Input.UnitTests
  6. {
  7. public class KeyboardNavigationTests_Tab
  8. {
  9. [Fact]
  10. public void Next_Continue_Returns_Next_Control_In_Container()
  11. {
  12. Button current;
  13. Button next;
  14. var top = new StackPanel
  15. {
  16. Children =
  17. {
  18. new StackPanel
  19. {
  20. Children =
  21. {
  22. new Button { Name = "Button1" },
  23. (current = new Button { Name = "Button2" }),
  24. (next = new Button { Name = "Button3" }),
  25. }
  26. },
  27. new StackPanel
  28. {
  29. Children =
  30. {
  31. new Button { Name = "Button4" },
  32. new Button { Name = "Button5" },
  33. new Button { Name = "Button6" },
  34. }
  35. },
  36. }
  37. };
  38. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  39. Assert.Equal(next, result);
  40. }
  41. [Fact]
  42. public void Next_Continue_Returns_First_Control_In_Next_Sibling_Container()
  43. {
  44. Button current;
  45. Button next;
  46. var top = new StackPanel
  47. {
  48. Children =
  49. {
  50. new StackPanel
  51. {
  52. Children =
  53. {
  54. new Button { Name = "Button1" },
  55. new Button { Name = "Button2" },
  56. (current = new Button { Name = "Button3" }),
  57. }
  58. },
  59. new StackPanel
  60. {
  61. Children =
  62. {
  63. (next = new Button { Name = "Button4" }),
  64. new Button { Name = "Button5" },
  65. new Button { Name = "Button6" },
  66. }
  67. },
  68. }
  69. };
  70. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  71. Assert.Equal(next, result);
  72. }
  73. [Fact]
  74. public void Next_Continue_Doesnt_Enter_Panel_With_TabNavigation_None()
  75. {
  76. Button current;
  77. Button next;
  78. var top = new StackPanel
  79. {
  80. Children =
  81. {
  82. new StackPanel
  83. {
  84. Children =
  85. {
  86. (next = new Button { Name = "Button1" }),
  87. new Button { Name = "Button2" },
  88. (current = new Button { Name = "Button3" }),
  89. }
  90. },
  91. new StackPanel
  92. {
  93. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.None,
  94. Children =
  95. {
  96. new StackPanel
  97. {
  98. Children =
  99. {
  100. new Button { Name = "Button4" },
  101. new Button { Name = "Button5" },
  102. new Button { Name = "Button6" },
  103. }
  104. },
  105. }
  106. }
  107. }
  108. };
  109. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  110. Assert.Equal(next, result);
  111. }
  112. [Fact]
  113. public void Next_Continue_Returns_Next_Sibling()
  114. {
  115. Button current;
  116. Button next;
  117. var top = new StackPanel
  118. {
  119. Children =
  120. {
  121. new StackPanel
  122. {
  123. Children =
  124. {
  125. new Button { Name = "Button1" },
  126. new Button { Name = "Button2" },
  127. (current = new Button { Name = "Button3" }),
  128. }
  129. },
  130. (next = new Button { Name = "Button4" }),
  131. }
  132. };
  133. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  134. Assert.Equal(next, result);
  135. }
  136. [Fact]
  137. public void Next_Continue_Returns_First_Control_In_Next_Uncle_Container()
  138. {
  139. Button current;
  140. Button next;
  141. var top = new StackPanel
  142. {
  143. Children =
  144. {
  145. new StackPanel
  146. {
  147. Children =
  148. {
  149. new StackPanel
  150. {
  151. Children =
  152. {
  153. new Button { Name = "Button1" },
  154. new Button { Name = "Button2" },
  155. (current = new Button { Name = "Button3" }),
  156. }
  157. },
  158. },
  159. },
  160. new StackPanel
  161. {
  162. Children =
  163. {
  164. (next = new Button { Name = "Button4" }),
  165. new Button { Name = "Button5" },
  166. new Button { Name = "Button6" },
  167. }
  168. },
  169. }
  170. };
  171. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  172. Assert.Equal(next, result);
  173. }
  174. [Fact]
  175. public void Next_Continue_Returns_Child_Of_Top_Level()
  176. {
  177. Button next;
  178. var top = new StackPanel
  179. {
  180. Children =
  181. {
  182. (next = new Button { Name = "Button1" }),
  183. }
  184. };
  185. var result = KeyboardNavigationHandler.GetNext(top, NavigationDirection.Next);
  186. Assert.Equal(next, result);
  187. }
  188. [Fact]
  189. public void Next_Continue_Wraps()
  190. {
  191. Button current;
  192. Button next;
  193. var top = new StackPanel
  194. {
  195. Children =
  196. {
  197. new StackPanel
  198. {
  199. Children =
  200. {
  201. new StackPanel
  202. {
  203. Children =
  204. {
  205. (next = new Button { Name = "Button1" }),
  206. new Button { Name = "Button2" },
  207. new Button { Name = "Button3" },
  208. }
  209. },
  210. },
  211. },
  212. new StackPanel
  213. {
  214. Children =
  215. {
  216. new Button { Name = "Button4" },
  217. new Button { Name = "Button5" },
  218. (current = new Button { Name = "Button6" }),
  219. }
  220. },
  221. }
  222. };
  223. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  224. Assert.Equal(next, result);
  225. }
  226. [Fact]
  227. public void Next_Cycle_Returns_Next_Control_In_Container()
  228. {
  229. Button current;
  230. Button next;
  231. var top = new StackPanel
  232. {
  233. Children =
  234. {
  235. new StackPanel
  236. {
  237. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  238. Children =
  239. {
  240. new Button { Name = "Button1" },
  241. (current = new Button { Name = "Button2" }),
  242. (next = new Button { Name = "Button3" }),
  243. }
  244. },
  245. new StackPanel
  246. {
  247. Children =
  248. {
  249. new Button { Name = "Button4" },
  250. new Button { Name = "Button5" },
  251. new Button { Name = "Button6" },
  252. }
  253. },
  254. }
  255. };
  256. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  257. Assert.Equal(next, result);
  258. }
  259. [Fact]
  260. public void Next_Cycle_Wraps_To_First()
  261. {
  262. Button current;
  263. Button next;
  264. var top = new StackPanel
  265. {
  266. Children =
  267. {
  268. new StackPanel
  269. {
  270. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  271. Children =
  272. {
  273. (next = new Button { Name = "Button1" }),
  274. new Button { Name = "Button2" },
  275. (current = new Button { Name = "Button3" }),
  276. }
  277. },
  278. new StackPanel
  279. {
  280. Children =
  281. {
  282. new Button { Name = "Button4" },
  283. new Button { Name = "Button5" },
  284. new Button { Name = "Button6" },
  285. }
  286. },
  287. }
  288. };
  289. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  290. Assert.Equal(next, result);
  291. }
  292. [Fact]
  293. public void Next_Contained_Returns_Next_Control_In_Container()
  294. {
  295. Button current;
  296. Button next;
  297. var top = new StackPanel
  298. {
  299. Children =
  300. {
  301. new StackPanel
  302. {
  303. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  304. Children =
  305. {
  306. new Button { Name = "Button1" },
  307. (current = new Button { Name = "Button2" }),
  308. (next = new Button { Name = "Button3" }),
  309. }
  310. },
  311. new StackPanel
  312. {
  313. Children =
  314. {
  315. new Button { Name = "Button4" },
  316. new Button { Name = "Button5" },
  317. new Button { Name = "Button6" },
  318. }
  319. },
  320. }
  321. };
  322. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  323. Assert.Equal(next, result);
  324. }
  325. [Fact]
  326. public void Next_Contained_Stops_At_End()
  327. {
  328. Button current;
  329. var top = new StackPanel
  330. {
  331. Children =
  332. {
  333. new StackPanel
  334. {
  335. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  336. Children =
  337. {
  338. new Button { Name = "Button1" },
  339. new Button { Name = "Button2" },
  340. (current = new Button { Name = "Button3" }),
  341. }
  342. },
  343. new StackPanel
  344. {
  345. Children =
  346. {
  347. new Button { Name = "Button4" },
  348. new Button { Name = "Button5" },
  349. new Button { Name = "Button6" },
  350. }
  351. },
  352. }
  353. };
  354. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  355. Assert.Null(result);
  356. }
  357. [Fact]
  358. public void Next_Once_Moves_To_Next_Container()
  359. {
  360. Button current;
  361. Button next;
  362. var top = new StackPanel
  363. {
  364. Children =
  365. {
  366. new StackPanel
  367. {
  368. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  369. Children =
  370. {
  371. new Button { Name = "Button1" },
  372. (current = new Button { Name = "Button2" }),
  373. new Button { Name = "Button3" },
  374. }
  375. },
  376. new StackPanel
  377. {
  378. Children =
  379. {
  380. (next = new Button { Name = "Button4" }),
  381. new Button { Name = "Button5" },
  382. new Button { Name = "Button6" },
  383. }
  384. },
  385. }
  386. };
  387. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  388. Assert.Equal(next, result);
  389. }
  390. [Fact]
  391. public void Next_Once_Moves_To_Active_Element()
  392. {
  393. StackPanel container;
  394. Button current;
  395. Button next;
  396. var top = new StackPanel
  397. {
  398. Children =
  399. {
  400. (container = new StackPanel
  401. {
  402. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  403. Children =
  404. {
  405. new Button { Name = "Button1" },
  406. (next = new Button { Name = "Button2" }),
  407. new Button { Name = "Button3" },
  408. }
  409. }),
  410. new StackPanel
  411. {
  412. Children =
  413. {
  414. new Button { Name = "Button4" },
  415. new Button { Name = "Button5" },
  416. (current = new Button { Name = "Button6" }),
  417. }
  418. },
  419. }
  420. };
  421. KeyboardNavigation.SetTabOnceActiveElement(container, next);
  422. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  423. Assert.Equal(next, result);
  424. }
  425. [Fact]
  426. public void Next_None_Moves_To_Next_Container()
  427. {
  428. Button current;
  429. Button next;
  430. var top = new StackPanel
  431. {
  432. Children =
  433. {
  434. new StackPanel
  435. {
  436. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.None,
  437. Children =
  438. {
  439. new Button { Name = "Button1" },
  440. (current = new Button { Name = "Button2" }),
  441. new Button { Name = "Button3" },
  442. }
  443. },
  444. new StackPanel
  445. {
  446. Children =
  447. {
  448. (next = new Button { Name = "Button4" }),
  449. new Button { Name = "Button5" },
  450. new Button { Name = "Button6" },
  451. }
  452. },
  453. }
  454. };
  455. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  456. Assert.Equal(next, result);
  457. }
  458. [Fact]
  459. public void Next_None_Skips_Container()
  460. {
  461. StackPanel container;
  462. Button current;
  463. Button next;
  464. var top = new StackPanel
  465. {
  466. Children =
  467. {
  468. (container = new StackPanel
  469. {
  470. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.None,
  471. Children =
  472. {
  473. new Button { Name = "Button1" },
  474. new Button { Name = "Button2" },
  475. new Button { Name = "Button3" },
  476. }
  477. }),
  478. new StackPanel
  479. {
  480. Children =
  481. {
  482. (next = new Button { Name = "Button4" }),
  483. new Button { Name = "Button5" },
  484. (current = new Button { Name = "Button6" }),
  485. }
  486. },
  487. }
  488. };
  489. KeyboardNavigation.SetTabOnceActiveElement(container, next);
  490. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Next);
  491. Assert.Equal(next, result);
  492. }
  493. [Fact]
  494. public void Previous_Continue_Returns_Previous_Control_In_Container()
  495. {
  496. Button current;
  497. Button next;
  498. var top = new StackPanel
  499. {
  500. Children =
  501. {
  502. new StackPanel
  503. {
  504. Children =
  505. {
  506. new Button { Name = "Button1" },
  507. (next = new Button { Name = "Button2" }),
  508. (current = new Button { Name = "Button3" }),
  509. }
  510. },
  511. new StackPanel
  512. {
  513. Children =
  514. {
  515. new Button { Name = "Button4" },
  516. new Button { Name = "Button5" },
  517. new Button { Name = "Button6" },
  518. }
  519. },
  520. }
  521. };
  522. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  523. Assert.Equal(next, result);
  524. }
  525. [Fact]
  526. public void Previous_Continue_Returns_Last_Control_In_Previous_Sibling_Container()
  527. {
  528. Button current;
  529. Button next;
  530. var top = new StackPanel
  531. {
  532. Children =
  533. {
  534. new StackPanel
  535. {
  536. Children =
  537. {
  538. new Button { Name = "Button1" },
  539. new Button { Name = "Button2" },
  540. (next = new Button { Name = "Button3" }),
  541. }
  542. },
  543. new StackPanel
  544. {
  545. Children =
  546. {
  547. (current = new Button { Name = "Button4" }),
  548. new Button { Name = "Button5" },
  549. new Button { Name = "Button6" },
  550. }
  551. },
  552. }
  553. };
  554. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  555. Assert.Equal(next, result);
  556. }
  557. [Fact]
  558. public void Previous_Continue_Returns_Last_Child_Of_Sibling()
  559. {
  560. Button current;
  561. Button next;
  562. var top = new StackPanel
  563. {
  564. Children =
  565. {
  566. new StackPanel
  567. {
  568. Children =
  569. {
  570. new Button { Name = "Button1" },
  571. new Button { Name = "Button2" },
  572. (next = new Button { Name = "Button3" }),
  573. }
  574. },
  575. (current = new Button { Name = "Button4" }),
  576. }
  577. };
  578. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  579. Assert.Equal(next, result);
  580. }
  581. [Fact]
  582. public void Previous_Continue_Returns_Last_Control_In_Previous_Nephew_Container()
  583. {
  584. Button current;
  585. Button next;
  586. var top = new StackPanel
  587. {
  588. Children =
  589. {
  590. new StackPanel
  591. {
  592. Children =
  593. {
  594. new StackPanel
  595. {
  596. Children =
  597. {
  598. new Button { Name = "Button1" },
  599. new Button { Name = "Button2" },
  600. (next = new Button { Name = "Button3" }),
  601. }
  602. },
  603. },
  604. },
  605. new StackPanel
  606. {
  607. Children =
  608. {
  609. (current = new Button { Name = "Button4" }),
  610. new Button { Name = "Button5" },
  611. new Button { Name = "Button6" },
  612. }
  613. },
  614. }
  615. };
  616. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  617. Assert.Equal(next, result);
  618. }
  619. [Fact]
  620. public void Previous_Continue_Wraps()
  621. {
  622. Button current;
  623. Button next;
  624. var top = new StackPanel
  625. {
  626. Children =
  627. {
  628. new StackPanel
  629. {
  630. Children =
  631. {
  632. new StackPanel
  633. {
  634. Children =
  635. {
  636. (current = new Button { Name = "Button1" }),
  637. new Button { Name = "Button2" },
  638. new Button { Name = "Button3" },
  639. }
  640. },
  641. },
  642. },
  643. new StackPanel
  644. {
  645. Children =
  646. {
  647. new Button { Name = "Button4" },
  648. new Button { Name = "Button5" },
  649. (next = new Button { Name = "Button6" }),
  650. }
  651. },
  652. }
  653. };
  654. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  655. Assert.Equal(next, result);
  656. }
  657. [Fact]
  658. public void Previous_Continue_Returns_Parent()
  659. {
  660. Button current;
  661. var top = new Decorator
  662. {
  663. Focusable = true,
  664. Child = current = new Button
  665. {
  666. Name = "Button",
  667. }
  668. };
  669. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  670. Assert.Equal(top, result);
  671. }
  672. [Fact]
  673. public void Previous_Cycle_Returns_Previous_Control_In_Container()
  674. {
  675. Button current;
  676. Button next;
  677. var top = new StackPanel
  678. {
  679. Children =
  680. {
  681. new StackPanel
  682. {
  683. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  684. Children =
  685. {
  686. (next = new Button { Name = "Button1" }),
  687. (current = new Button { Name = "Button2" }),
  688. new Button { Name = "Button3" },
  689. }
  690. },
  691. new StackPanel
  692. {
  693. Children =
  694. {
  695. new Button { Name = "Button4" },
  696. new Button { Name = "Button5" },
  697. new Button { Name = "Button6" },
  698. }
  699. },
  700. }
  701. };
  702. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  703. Assert.Equal(next, result);
  704. }
  705. [Fact]
  706. public void Previous_Cycle_Wraps_To_Last()
  707. {
  708. Button current;
  709. Button next;
  710. var top = new StackPanel
  711. {
  712. Children =
  713. {
  714. new StackPanel
  715. {
  716. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Cycle,
  717. Children =
  718. {
  719. (current = new Button { Name = "Button1" }),
  720. new Button { Name = "Button2" },
  721. (next = new Button { Name = "Button3" }),
  722. }
  723. },
  724. new StackPanel
  725. {
  726. Children =
  727. {
  728. new Button { Name = "Button4" },
  729. new Button { Name = "Button5" },
  730. new Button { Name = "Button6" },
  731. }
  732. },
  733. }
  734. };
  735. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  736. Assert.Equal(next, result);
  737. }
  738. [Fact]
  739. public void Previous_Contained_Returns_Previous_Control_In_Container()
  740. {
  741. Button current;
  742. Button next;
  743. var top = new StackPanel
  744. {
  745. Children =
  746. {
  747. new StackPanel
  748. {
  749. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  750. Children =
  751. {
  752. (next = new Button { Name = "Button1" }),
  753. (current = new Button { Name = "Button2" }),
  754. new Button { Name = "Button3" },
  755. }
  756. },
  757. new StackPanel
  758. {
  759. Children =
  760. {
  761. new Button { Name = "Button4" },
  762. new Button { Name = "Button5" },
  763. new Button { Name = "Button6" },
  764. }
  765. },
  766. }
  767. };
  768. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  769. Assert.Equal(next, result);
  770. }
  771. [Fact]
  772. public void Previous_Contained_Stops_At_Beginning()
  773. {
  774. Button current;
  775. var top = new StackPanel
  776. {
  777. Children =
  778. {
  779. new StackPanel
  780. {
  781. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  782. Children =
  783. {
  784. (current = new Button { Name = "Button1" }),
  785. new Button { Name = "Button2" },
  786. new Button { Name = "Button3" },
  787. }
  788. },
  789. new StackPanel
  790. {
  791. Children =
  792. {
  793. new Button { Name = "Button4" },
  794. new Button { Name = "Button5" },
  795. new Button { Name = "Button6" },
  796. }
  797. },
  798. }
  799. };
  800. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  801. Assert.Null(result);
  802. }
  803. [Fact]
  804. public void Previous_Once_Moves_To_Previous_Container()
  805. {
  806. Button current;
  807. Button next;
  808. var top = new StackPanel
  809. {
  810. Children =
  811. {
  812. new StackPanel
  813. {
  814. Children =
  815. {
  816. new Button { Name = "Button1" },
  817. new Button { Name = "Button2" },
  818. (next = new Button { Name = "Button3" }),
  819. }
  820. },
  821. new StackPanel
  822. {
  823. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  824. Children =
  825. {
  826. new Button { Name = "Button4" },
  827. (current = new Button { Name = "Button5" }),
  828. new Button { Name = "Button6" },
  829. }
  830. },
  831. }
  832. };
  833. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  834. Assert.Equal(next, result);
  835. }
  836. [Fact]
  837. public void Previous_Once_Moves_To_Active_Element()
  838. {
  839. StackPanel container;
  840. Button current;
  841. Button next;
  842. var top = new StackPanel
  843. {
  844. Children =
  845. {
  846. (container = new StackPanel
  847. {
  848. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  849. Children =
  850. {
  851. new Button { Name = "Button1" },
  852. (next = new Button { Name = "Button2" }),
  853. new Button { Name = "Button3" },
  854. }
  855. }),
  856. new StackPanel
  857. {
  858. Children =
  859. {
  860. (current = new Button { Name = "Button4" }),
  861. new Button { Name = "Button5" },
  862. new Button { Name = "Button6" },
  863. }
  864. },
  865. }
  866. };
  867. KeyboardNavigation.SetTabOnceActiveElement(container, next);
  868. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  869. Assert.Equal(next, result);
  870. }
  871. [Fact]
  872. public void Previous_Once_Moves_To_First_Element()
  873. {
  874. Button current;
  875. Button next;
  876. var top = new StackPanel
  877. {
  878. Children =
  879. {
  880. new StackPanel
  881. {
  882. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Once,
  883. Children =
  884. {
  885. (next = new Button { Name = "Button1" }),
  886. new Button { Name = "Button2" },
  887. new Button { Name = "Button3" },
  888. }
  889. },
  890. new StackPanel
  891. {
  892. Children =
  893. {
  894. (current = new Button { Name = "Button4" }),
  895. new Button { Name = "Button5" },
  896. new Button { Name = "Button6" },
  897. }
  898. },
  899. }
  900. };
  901. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  902. Assert.Equal(next, result);
  903. }
  904. [Fact]
  905. public void Previous_Contained_Doesnt_Select_Child_Control()
  906. {
  907. Decorator current;
  908. var top = new StackPanel
  909. {
  910. [KeyboardNavigation.TabNavigationProperty] = KeyboardNavigationMode.Contained,
  911. Children =
  912. {
  913. (current = new Decorator
  914. {
  915. Focusable = true,
  916. Child = new Button(),
  917. })
  918. }
  919. };
  920. var result = KeyboardNavigationHandler.GetNext(current, NavigationDirection.Previous);
  921. Assert.Null(result);
  922. }
  923. }
  924. }