KeyboardNavigationTests_Tab.cs 34 KB

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