Guest User

Untitled

a guest
Nov 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. public class BaseViewModel : NotifyPropertyChanged
  2. {
  3. static BaseViewModel()
  4. {
  5. if (LangResourceLoader.Instance.CurrentLanguageAbbr == LanguageCode.Arabic)
  6. {
  7. _flowDirection = FlowDirection.RightToLeft;
  8. }
  9. else
  10. {
  11. _flowDirection = FlowDirection.LeftToRight;
  12. }
  13. }
  14.  
  15. public BaseViewModel()
  16. {
  17. Language.PropertyChanged += (sender, e) =>
  18. {
  19. if (Language.CurrentLanguageAbbr == LanguageCode.Arabic)
  20. {
  21. FlowDirection = FlowDirection.RightToLeft;
  22. }
  23. else
  24. {
  25. FlowDirection = FlowDirection.LeftToRight;
  26. }
  27. };
  28. }
  29.  
  30. private Page _page;
  31. public Page Page
  32. {
  33. get
  34. {
  35. return _page;
  36. }
  37. }
  38.  
  39. public LangResourceLoader Language
  40. {
  41. get
  42. {
  43. return LangResourceLoader.Instance;
  44. }
  45. }
  46.  
  47. private static FlowDirection _flowDirection = Device.FlowDirection;
  48. public FlowDirection FlowDirection
  49. {
  50. get
  51. {
  52. return _flowDirection;
  53. }
  54. set
  55. {
  56. _flowDirection = value;
  57. if (_page != null)
  58. {
  59. _page.FlowDirection = _flowDirection;
  60. }
  61. OnPropertyChanged("FlowDirection");
  62. }
  63. }
  64.  
  65. VisualElement _visualElement;
  66. public VisualElement VisualElement
  67. {
  68. get
  69. {
  70. return _visualElement;
  71. }
  72. set
  73. {
  74. if (_visualElement != value && value != null)
  75. {
  76. _visualElement = value;
  77. var p = Page;
  78.  
  79. if (_visualElement is Page page)
  80. {
  81. _page = page;
  82. }
  83.  
  84. if (_visualElement.BindingContext == null)
  85. {
  86. _visualElement.BindingContext = this;
  87. }
  88.  
  89. if (_page != null)
  90. {
  91. _page.FlowDirection = FlowDirection;
  92. }
  93.  
  94. OnPropertyChanged("VisualElement");
  95. }
  96. }
  97. }
  98. }
Add Comment
Please, Sign In to add comment