public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double scaleFactor = 0.0; if (!String.IsNullOrEmpty((string)value)) { double diagonalScreenSize = System.Convert.ToDouble(value, culture); Point scale = DipHelper.GetScreenIndependentScaleFactor(diagonalScreenSize); Point physicalDpi = DipHelper.GetPhysicalDpi(diagonalScreenSize); string sParameter = (string)parameter; if (sParameter == "ScaleY") { scaleFactor = scale.Y; } else if (sParameter == "ScaleX") { scaleFactor = scale.X; } else if (sParameter == "PhysicalDpi") { scaleFactor = physicalDpi.X; } } return(scaleFactor); }
private void Page_Loaded(object sender, RoutedEventArgs e) { Point systemDpi = DipHelper.GetSystemDpi(); tbSystemDpiValueText.Text = systemDpi.X.ToString(); sScreenSize.Value = DipHelper.ScreenSize; }
public void setruler(double x, double y) { //主标尺系统 double mainchip = DipHelper.GetRulerMileage(x); //显示隧道主洞桩号 hruler.Chip = mainchip; int i = (int)Math.Round(mainchip); string st = i.ToString(); string st1 = st.Substring(0, st.Length - 3); if ((st1 == null) || (st1 == "")) { st1 = "0"; } string st2 = st.Substring(st.Length - 3); if (partchar == '左') { st = "ZK" + st1 + "+" + st2; } else { st = "YK" + st1 + "+" + st2; } MapCoordsZH.Text = "桩号:" + st; //显示沿桩衬砌 mili_ruler.Chip = mainchip; //显示高程信息 double heightchip = DipHelper.GetRulerAltitude(y); vruler.Chip = heightchip; st = Math.Round(heightchip).ToString(); MapCoordsGC.Text = "高程:" + st + "米"; //显示斜井桩号 int pile = DipHelper.GetRulerXJMileage(Convert.ToInt32(x)); xjruler.Chip = x; string temp; if (x < 3250) { temp = "BX"; } else { temp = "LX"; } if (pile >= 0) { st = pile.ToString().PadLeft(4, '0'); st2 = st.Substring(st.Length - 3); st = temp + "K" + st[0] + "+" + st2; MapCoordsXJ.Text = "斜井桩号:" + st; } }
/// <summary> /// Measures an instance during the first layout pass prior to arranging it. /// </summary> /// <param name="availableSize">A maximum Size to not exceed.</param> /// <returns>The maximum Size for the instance.</returns> protected override Size MeasureOverride(Size availableSize) { Size desiredSize; if (Unit == Unit.Cm) { desiredSize = new Size(DipHelper.CmToDip(Length), this.Height); } else { desiredSize = new Size(DipHelper.InchToDip(Length), this.Height); } return(desiredSize); }
public void UsesDipMultiplier() { double dipMultiplier = DipHelper.GetDipMultiplier(); double input = 10; double expectedOutput = input * dipMultiplier; var gridUnitExtension = new GridUnitExtension(input.ToString()) { MultiplyWithDip = true, GridCellSize = 1 // This must be 1, otherwise the result will be multiplied }; // by 4 (default). double result = (double)gridUnitExtension.ProvideValue(MockedServiceProvider.Default); Assert.Equal(expectedOutput, result); }
/// <summary> /// Participates in rendering operations. /// </summary> /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param> protected override void OnRender(System.Windows.Media.DrawingContext drawingContext) { base.OnRender(drawingContext); double xDest; if (Unit == Unit.Cm) { xDest = DipHelper.CmToDip(Length); } else { xDest = DipHelper.InchToDip(Length); } drawingContext.DrawRectangle(null, _pBorder, new Rect(new Point(0.0, 0.0), new Point(xDest, this.Height))); for (double dUnit = 0.0; dUnit <= Length; dUnit++) { double d; if (Unit == Unit.Cm) { d = DipHelper.CmToDip(dUnit); if (dUnit < Length) { for (int i = 1; i <= 9; i++) { if (i != 5) { double dMm = DipHelper.CmToDip(dUnit + 0.1 * i); drawingContext.DrawLine(_pThin, new Point(dMm, this.Height), new Point(dMm, this.Height - _segmentHeight / 3.0)); } } double dMiddle = DipHelper.CmToDip(dUnit + 0.5); drawingContext.DrawLine(_p, new Point(dMiddle, this.Height), new Point(dMiddle, this.Height - _segmentHeight * 2.0 / 3.0)); } } else { d = DipHelper.InchToDip(dUnit); if (dUnit < Length) { double dQuarter = DipHelper.InchToDip(dUnit + 0.25); drawingContext.DrawLine(_pThin, new Point(dQuarter, this.Height), new Point(dQuarter, this.Height - _segmentHeight / 3.0)); double dMiddle = DipHelper.InchToDip(dUnit + 0.5); drawingContext.DrawLine(_p, new Point(dMiddle, this.Height), new Point(dMiddle, this.Height - 0.5 * _segmentHeight * 2.0 / 3.0)); double d3Quarter = DipHelper.InchToDip(dUnit + 0.75); drawingContext.DrawLine(_pThin, new Point(d3Quarter, this.Height), new Point(d3Quarter, this.Height - 0.25 * _segmentHeight / 3.0)); } } drawingContext.DrawLine(_p, new Point(d, this.Height), new Point(d, this.Height - _segmentHeight)); if ((dUnit != 0.0) && (dUnit < Length)) { FormattedText ft = new FormattedText( dUnit.ToString(CultureInfo.CurrentCulture), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), DipHelper.PtToDip(10.0), Brushes.Black); ft.SetFontWeight(FontWeights.Regular); ft.TextAlignment = TextAlignment.Center; drawingContext.DrawText(ft, new Point(d, this.Height - _segmentHeight - ft.Height)); } } }