Legend.Properties.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. // --------------------------------------------------------------------------------------------------------------------
  2. // <copyright file="Legend.Properties.cs" company="OxyPlot">
  3. // Copyright (c) 2020 OxyPlot contributors
  4. // </copyright>
  5. // <summary>
  6. // Represents a control that displays a <see cref="OxyPlot.Legends.Legend" />.
  7. // </summary>
  8. // --------------------------------------------------------------------------------------------------------------------
  9. using Avalonia;
  10. namespace OxyPlot.Avalonia
  11. {
  12. using global::Avalonia.Controls;
  13. using global::Avalonia.Media;
  14. using OxyPlot.Legends;
  15. /// <summary>
  16. /// Represents a control that displays a <see cref="OxyPlot.Legends.Legend" />.
  17. /// </summary>
  18. /// <remarks>This file contains dependency properties used for defining the Plot in XAML. These properties are only used when Model is <c>null</c>. In this case an internal PlotModel is created and the dependency properties are copied from the control to the internal Legend.</remarks>
  19. public partial class Legend : Control
  20. {
  21. /// <summary>
  22. /// Identifies the <see cref="IsLegendVisible"/> dependency property.
  23. /// </summary>
  24. public static readonly StyledProperty<bool> IsLegendVisibleProperty = AvaloniaProperty.Register<Legend, bool>(nameof(IsLegendVisible), true);
  25. /// <summary>
  26. /// Identifies the <see cref="LegendBackground"/> dependency property.
  27. /// </summary>
  28. public static readonly StyledProperty<Color> LegendBackgroundProperty = AvaloniaProperty.Register<Legend, Color>(nameof(LegendBackground), MoreColors.Undefined);
  29. /// <summary>
  30. /// Identifies the <see cref="LegendBorder"/> dependency property.
  31. /// </summary>
  32. public static readonly StyledProperty<Color> LegendBorderProperty = AvaloniaProperty.Register<Legend, Color>(nameof(LegendBorder), MoreColors.Undefined);
  33. /// <summary>
  34. /// Identifies the <see cref="LegendBorderThickness"/> dependency property.
  35. /// </summary>
  36. public static readonly StyledProperty<double> LegendBorderThicknessProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendBorderThickness), 1.0);
  37. /// <summary>
  38. /// Identifies the <see cref="LegendFont"/> dependency property.
  39. /// </summary>
  40. public static readonly StyledProperty<string> LegendFontProperty = AvaloniaProperty.Register<Legend, string>(nameof(LegendFont), null);
  41. /// <summary>
  42. /// Identifies the <see cref="LegendFontSize"/> dependency property.
  43. /// </summary>
  44. public static readonly StyledProperty<double> LegendFontSizeProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendFontSize), 12.0);
  45. /// <summary>
  46. /// Identifies the <see cref="LegendFontWeight"/> dependency property.
  47. /// </summary>
  48. public static readonly StyledProperty<FontWeight> LegendFontWeightProperty = AvaloniaProperty.Register<Legend, FontWeight>(nameof(LegendFontWeight), FontWeight.Normal);
  49. /// <summary>
  50. /// Identifies the <see cref="LegendItemAlignment"/> dependency property.
  51. /// </summary>
  52. public static readonly StyledProperty<global::Avalonia.Layout.HorizontalAlignment> LegendItemAlignmentProperty = AvaloniaProperty.Register<Legend, global::Avalonia.Layout.HorizontalAlignment>(nameof(LegendItemAlignment), global::Avalonia.Layout.HorizontalAlignment.Left);
  53. /// <summary>
  54. /// Identifies the <see cref="LegendItemOrder"/> dependency property.
  55. /// </summary>
  56. public static readonly StyledProperty<LegendItemOrder> LegendItemOrderProperty = AvaloniaProperty.Register<Legend, LegendItemOrder>(nameof(LegendItemOrder), LegendItemOrder.Normal);
  57. /// <summary>
  58. /// Identifies the <see cref="LegendItemSpacing"/> dependency property.
  59. /// </summary>
  60. public static readonly StyledProperty<double> LegendItemSpacingProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendItemSpacing), 24.0);
  61. /// <summary>
  62. /// Identifies the <see cref="LegendLineSpacing"/> dependency property.
  63. /// </summary>
  64. public static readonly StyledProperty<double> LegendLineSpacingProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendLineSpacing), 0d);
  65. /// <summary>
  66. /// Identifies the <see cref="LegendMargin"/> dependency property.
  67. /// </summary>
  68. public static readonly StyledProperty<double> LegendMarginProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendMargin), 8.0);
  69. /// <summary>
  70. /// Identifies the <see cref="LegendMaxHeight"/> dependency property.
  71. /// </summary>
  72. public static readonly StyledProperty<double> LegendMaxHeightProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendMaxHeight), double.NaN);
  73. /// <summary>
  74. /// Identifies the <see cref="LegendMaxWidth"/> dependency property.
  75. /// </summary>
  76. public static readonly StyledProperty<double> LegendMaxWidthProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendMaxWidth), double.NaN);
  77. /// <summary>
  78. /// Identifies the <see cref="LegendOrientation"/> dependency property.
  79. /// </summary>
  80. public static readonly StyledProperty<LegendOrientation> LegendOrientationProperty = AvaloniaProperty.Register<Legend, LegendOrientation>(nameof(LegendOrientation), LegendOrientation.Vertical);
  81. /// <summary>
  82. /// Identifies the <see cref="LegendColumnSpacing"/> dependency property.
  83. /// </summary>
  84. public static readonly StyledProperty<double> LegendColumnSpacingProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendColumnSpacing), 8.0);
  85. /// <summary>
  86. /// Identifies the <see cref="LegendPadding"/> dependency property.
  87. /// </summary>
  88. public static readonly StyledProperty<double> LegendPaddingProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendPadding), 8.0);
  89. /// <summary>
  90. /// Identifies the <see cref="LegendPlacement"/> dependency property.
  91. /// </summary>
  92. public static readonly StyledProperty<LegendPlacement> LegendPlacementProperty = AvaloniaProperty.Register<Legend, LegendPlacement>(nameof(LegendPlacement), LegendPlacement.Inside);
  93. /// <summary>
  94. /// Identifies the <see cref="LegendPosition"/> dependency property.
  95. /// </summary>
  96. public static readonly StyledProperty<LegendPosition> LegendPositionProperty = AvaloniaProperty.Register<Legend, LegendPosition>(nameof(LegendPosition), LegendPosition.RightTop);
  97. /// <summary>
  98. /// Identifies the <see cref="LegendSymbolLength"/> dependency property.
  99. /// </summary>
  100. public static readonly StyledProperty<double> LegendSymbolLengthProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendSymbolLength), 16.0);
  101. /// <summary>
  102. /// Identifies the <see cref="LegendSymbolMargin"/> dependency property.
  103. /// </summary>
  104. public static readonly StyledProperty<double> LegendSymbolMarginProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendSymbolMargin), 4.0);
  105. /// <summary>
  106. /// Identifies the <see cref="LegendSymbolPlacement"/> dependency property.
  107. /// </summary>
  108. public static readonly StyledProperty<LegendSymbolPlacement> LegendSymbolPlacementProperty = AvaloniaProperty.Register<Legend, LegendSymbolPlacement>(nameof(LegendSymbolPlacement), LegendSymbolPlacement.Left);
  109. /// <summary>
  110. /// Identifies the <see cref="LegendTextColor"/> dependency property.
  111. /// </summary>
  112. public static readonly StyledProperty<Color> LegendTextColorProperty = AvaloniaProperty.Register<Legend, Color>(nameof(LegendTextColor), MoreColors.Automatic);
  113. /// <summary>
  114. /// Identifies the <see cref="LegendTitle"/> dependency property.
  115. /// </summary>
  116. public static readonly StyledProperty<string> LegendTitleProperty = AvaloniaProperty.Register<Legend, string>(nameof(LegendTitle), null);
  117. /// <summary>
  118. /// Identifies the <see cref="LegendTextColor"/> dependency property.
  119. /// </summary>
  120. public static readonly StyledProperty<Color> LegendTitleColorProperty = AvaloniaProperty.Register<Legend, Color>(nameof(LegendTitleColor), MoreColors.Automatic);
  121. /// <summary>
  122. /// Identifies the <see cref="LegendTitleFont"/> dependency property.
  123. /// </summary>
  124. public static readonly StyledProperty<string> LegendTitleFontProperty = AvaloniaProperty.Register<Legend, string>(nameof(LegendTitleFont), null);
  125. /// <summary>
  126. /// Identifies the <see cref="LegendTitleFontSize"/> dependency property.
  127. /// </summary>
  128. public static readonly StyledProperty<double> LegendTitleFontSizeProperty = AvaloniaProperty.Register<Legend, double>(nameof(LegendTitleFontSize), 12.0);
  129. /// <summary>
  130. /// Identifies the <see cref="LegendTitleFontWeight"/> dependency property.
  131. /// </summary>
  132. public static readonly StyledProperty<FontWeight> LegendTitleFontWeightProperty = AvaloniaProperty.Register<Legend, FontWeight>(nameof(LegendTitleFontWeight), FontWeight.Bold);
  133. /// <summary>
  134. /// Identifies the <see cref="EdgeRenderingMode"/> dependency property.
  135. /// </summary>
  136. public static readonly StyledProperty<EdgeRenderingMode> EdgeRenderingModeProperty = AvaloniaProperty.Register<Legend, EdgeRenderingMode>(nameof(EdgeRenderingMode), EdgeRenderingMode.Automatic);
  137. /// <summary>
  138. /// Gets or sets LegendBackground.
  139. /// </summary>
  140. public Color LegendBackground
  141. {
  142. get
  143. {
  144. return GetValue(LegendBackgroundProperty);
  145. }
  146. set
  147. {
  148. SetValue(LegendBackgroundProperty, value);
  149. }
  150. }
  151. /// <summary>
  152. /// Gets or sets LegendBorder.
  153. /// </summary>
  154. public Color LegendBorder
  155. {
  156. get
  157. {
  158. return GetValue(LegendBorderProperty);
  159. }
  160. set
  161. {
  162. SetValue(LegendBorderProperty, value);
  163. }
  164. }
  165. /// <summary>
  166. /// Gets or sets LegendBorderThickness.
  167. /// </summary>
  168. public double LegendBorderThickness
  169. {
  170. get
  171. {
  172. return GetValue(LegendBorderThicknessProperty);
  173. }
  174. set
  175. {
  176. SetValue(LegendBorderThicknessProperty, value);
  177. }
  178. }
  179. /// <summary>
  180. /// Gets or sets the spacing between columns of legend items (only for vertical orientation).
  181. /// </summary>
  182. /// <value>The spacing in device independent units.</value>
  183. public double LegendColumnSpacing
  184. {
  185. get
  186. {
  187. return GetValue(LegendColumnSpacingProperty);
  188. }
  189. set
  190. {
  191. SetValue(LegendColumnSpacingProperty, value);
  192. }
  193. }
  194. /// <summary>
  195. /// Gets or sets LegendFont.
  196. /// </summary>
  197. public string LegendFont
  198. {
  199. get
  200. {
  201. return GetValue(LegendFontProperty);
  202. }
  203. set
  204. {
  205. SetValue(LegendFontProperty, value);
  206. }
  207. }
  208. /// <summary>
  209. /// Gets or sets LegendFontSize.
  210. /// </summary>
  211. public double LegendFontSize
  212. {
  213. get
  214. {
  215. return GetValue(LegendFontSizeProperty);
  216. }
  217. set
  218. {
  219. SetValue(LegendFontSizeProperty, value);
  220. }
  221. }
  222. /// <summary>
  223. /// Gets or sets LegendFontWeight.
  224. /// </summary>
  225. public FontWeight LegendFontWeight
  226. {
  227. get
  228. {
  229. return GetValue(LegendFontWeightProperty);
  230. }
  231. set
  232. {
  233. SetValue(LegendFontWeightProperty, value);
  234. }
  235. }
  236. /// <summary>
  237. /// Gets or sets LegendItemAlignment.
  238. /// </summary>
  239. public global::Avalonia.Layout.HorizontalAlignment LegendItemAlignment
  240. {
  241. get
  242. {
  243. return GetValue(LegendItemAlignmentProperty);
  244. }
  245. set
  246. {
  247. SetValue(LegendItemAlignmentProperty, value);
  248. }
  249. }
  250. /// <summary>
  251. /// Gets or sets LegendItemOrder.
  252. /// </summary>
  253. public LegendItemOrder LegendItemOrder
  254. {
  255. get
  256. {
  257. return GetValue(LegendItemOrderProperty);
  258. }
  259. set
  260. {
  261. SetValue(LegendItemOrderProperty, value);
  262. }
  263. }
  264. /// <summary>
  265. /// Gets or sets the horizontal spacing between legend items when the orientation is horizontal.
  266. /// </summary>
  267. /// <value>The horizontal distance between items in device independent units.</value>
  268. public double LegendItemSpacing
  269. {
  270. get
  271. {
  272. return GetValue(LegendItemSpacingProperty);
  273. }
  274. set
  275. {
  276. SetValue(LegendItemSpacingProperty, value);
  277. }
  278. }
  279. /// <summary>
  280. /// Gets or sets the vertical spacing between legend items.
  281. /// </summary>
  282. /// <value>The spacing in device independent units.</value>
  283. public double LegendLineSpacing
  284. {
  285. get
  286. {
  287. return GetValue(LegendLineSpacingProperty);
  288. }
  289. set
  290. {
  291. SetValue(LegendLineSpacingProperty, value);
  292. }
  293. }
  294. /// <summary>
  295. /// Gets or sets the max height of the legend.
  296. /// </summary>
  297. /// <value>The max width of the legends.</value>
  298. public double LegendMaxHeight
  299. {
  300. get
  301. {
  302. return GetValue(LegendMaxHeightProperty);
  303. }
  304. set
  305. {
  306. SetValue(LegendMaxHeightProperty, value);
  307. }
  308. }
  309. /// <summary>
  310. /// Gets or sets the max width of the legend.
  311. /// </summary>
  312. /// <value>The max width of the legends.</value>
  313. public double LegendMaxWidth
  314. {
  315. get
  316. {
  317. return GetValue(LegendMaxWidthProperty);
  318. }
  319. set
  320. {
  321. SetValue(LegendMaxWidthProperty, value);
  322. }
  323. }
  324. /// <summary>
  325. /// Gets or sets LegendMargin.
  326. /// </summary>
  327. public double LegendMargin
  328. {
  329. get
  330. {
  331. return GetValue(LegendMarginProperty);
  332. }
  333. set
  334. {
  335. SetValue(LegendMarginProperty, value);
  336. }
  337. }
  338. /// <summary>
  339. /// Gets or sets LegendOrientation.
  340. /// </summary>
  341. public LegendOrientation LegendOrientation
  342. {
  343. get
  344. {
  345. return GetValue(LegendOrientationProperty);
  346. }
  347. set
  348. {
  349. SetValue(LegendOrientationProperty, value);
  350. }
  351. }
  352. /// <summary>
  353. /// Gets or sets the legend padding.
  354. /// </summary>
  355. public double LegendPadding
  356. {
  357. get
  358. {
  359. return GetValue(LegendPaddingProperty);
  360. }
  361. set
  362. {
  363. SetValue(LegendPaddingProperty, value);
  364. }
  365. }
  366. /// <summary>
  367. /// Gets or sets LegendPlacement.
  368. /// </summary>
  369. public LegendPlacement LegendPlacement
  370. {
  371. get
  372. {
  373. return GetValue(LegendPlacementProperty);
  374. }
  375. set
  376. {
  377. SetValue(LegendPlacementProperty, value);
  378. }
  379. }
  380. /// <summary>
  381. /// Gets or sets the legend position.
  382. /// </summary>
  383. /// <value>The legend position.</value>
  384. public LegendPosition LegendPosition
  385. {
  386. get
  387. {
  388. return GetValue(LegendPositionProperty);
  389. }
  390. set
  391. {
  392. SetValue(LegendPositionProperty, value);
  393. }
  394. }
  395. /// <summary>
  396. /// Gets or sets LegendSymbolLength.
  397. /// </summary>
  398. public double LegendSymbolLength
  399. {
  400. get
  401. {
  402. return GetValue(LegendSymbolLengthProperty);
  403. }
  404. set
  405. {
  406. SetValue(LegendSymbolLengthProperty, value);
  407. }
  408. }
  409. /// <summary>
  410. /// Gets or sets LegendSymbolMargin.
  411. /// </summary>
  412. public double LegendSymbolMargin
  413. {
  414. get
  415. {
  416. return GetValue(LegendSymbolMarginProperty);
  417. }
  418. set
  419. {
  420. SetValue(LegendSymbolMarginProperty, value);
  421. }
  422. }
  423. /// <summary>
  424. /// Gets or sets LegendSymbolPlacement.
  425. /// </summary>
  426. public LegendSymbolPlacement LegendSymbolPlacement
  427. {
  428. get
  429. {
  430. return GetValue(LegendSymbolPlacementProperty);
  431. }
  432. set
  433. {
  434. SetValue(LegendSymbolPlacementProperty, value);
  435. }
  436. }
  437. /// <summary>
  438. /// Gets or sets LegendTitleFont.
  439. /// </summary>
  440. public string LegendTitleFont
  441. {
  442. get
  443. {
  444. return GetValue(LegendTitleFontProperty);
  445. }
  446. set
  447. {
  448. SetValue(LegendTitleFontProperty, value);
  449. }
  450. }
  451. /// <summary>
  452. /// Gets or sets the text color of the legends.
  453. /// </summary>
  454. public Color LegendTextColor
  455. {
  456. get
  457. {
  458. return GetValue(LegendTextColorProperty);
  459. }
  460. set
  461. {
  462. SetValue(LegendTextColorProperty, value);
  463. }
  464. }
  465. /// <summary>
  466. /// Gets or sets the legend title.
  467. /// </summary>
  468. public string LegendTitle
  469. {
  470. get
  471. {
  472. return GetValue(LegendTitleProperty);
  473. }
  474. set
  475. {
  476. SetValue(LegendTitleProperty, value);
  477. }
  478. }
  479. /// <summary>
  480. /// Gets or sets color of the legend title.
  481. /// </summary>
  482. public Color LegendTitleColor
  483. {
  484. get
  485. {
  486. return GetValue(LegendTitleColorProperty);
  487. }
  488. set
  489. {
  490. SetValue(LegendTitleColorProperty, value);
  491. }
  492. }
  493. /// <summary>
  494. /// Gets or sets the font size of the legend titles.
  495. /// </summary>
  496. public double LegendTitleFontSize
  497. {
  498. get
  499. {
  500. return GetValue(LegendTitleFontSizeProperty);
  501. }
  502. set
  503. {
  504. SetValue(LegendTitleFontSizeProperty, value);
  505. }
  506. }
  507. /// <summary>
  508. /// Gets or sets the font weight of the legend titles.
  509. /// </summary>
  510. public FontWeight LegendTitleFontWeight
  511. {
  512. get
  513. {
  514. return GetValue(LegendTitleFontWeightProperty);
  515. }
  516. set
  517. {
  518. SetValue(LegendTitleFontWeightProperty, value);
  519. }
  520. }
  521. /// <summary>
  522. /// Gets or sets a value indicating whether the legend is visible.
  523. /// </summary>
  524. public bool IsLegendVisible
  525. {
  526. get
  527. {
  528. return GetValue(IsLegendVisibleProperty);
  529. }
  530. set
  531. {
  532. SetValue(IsLegendVisibleProperty, value);
  533. }
  534. }
  535. /// <summary>
  536. /// Gets or sets the <see cref="OxyPlot.EdgeRenderingMode"/> for the legend.
  537. /// </summary>
  538. public EdgeRenderingMode EdgeRenderingMode
  539. {
  540. get
  541. {
  542. return GetValue(EdgeRenderingModeProperty);
  543. }
  544. set
  545. {
  546. SetValue(EdgeRenderingModeProperty, value);
  547. }
  548. }
  549. }
  550. }