1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using ComPDFKit.Controls.Data;
- using System;
- using System.Linq;
- using System.Windows.Controls;
- using System.Windows.Media;
- using DashStyle = System.Windows.Media.DashStyle;
- namespace ComPDFKit.Controls.Common
- {
- public partial class CPDFLineStyleControl : UserControl
- {
- public event EventHandler LineStyleChanged;
- private DashStyle _dashStyle;
- public DashStyle DashStyle
- {
- get
- {
- _dashStyle = CalculateDashStyle(CPDFLineStyleUI.DashStyle);
- return _dashStyle;
- }
- set
- {
- _dashStyle = value;
- if(_dashStyle.Dashes.ToArray().Length == 0)
- {
- CPDFLineStyleUI.SolidRadioButton.IsChecked = true;
- CPDFLineStyleUI.IsSolid = true;
- CPDFLineStyleUI.DashSpacing = 1;
- }
- else
- {
- CPDFLineStyleUI.DashRadioButton.IsChecked = true;
- CPDFLineStyleUI.IsSolid = false;
- CPDFLineStyleUI.DashSpacing = (int)(_dashStyle.Dashes.ToArray().First());
- }
- }
- }
- public CPDFLineStyleControl()
- {
- InitializeComponent();
- CPDFLineStyleUI.LineStyleChanged -= CPDFLineStyleUI_LineStyleChanged;
- CPDFLineStyleUI.LineStyleChanged += CPDFLineStyleUI_LineStyleChanged;
- }
- public DashStyle CalculateDashStyle(CPDFDashData pdfDash)
- {
- DashStyle dashStyle = new DashStyle();
- if (pdfDash.IsSolid)
- {
- dashStyle = DashStyles.Solid;
- return dashStyle;
- }
- else
- {
- dashStyle.Dashes.Add(pdfDash.DashSpacing);
- dashStyle.Dashes.Add(pdfDash.DashSpacing);
- return dashStyle;
- }
- }
- private void CPDFLineStyleUI_LineStyleChanged(object sender, EventArgs e)
- {
- LineStyleChanged?.Invoke(this, EventArgs.Empty);
- }
- }
- }
|