Mürekkep Giriş Denetimi Oluşturma
Mürekkepleri dinamik ve statik olarak işleyici özel bir denetim oluşturabilirsiniz. Başka bir ifadeyle, bir kullanıcı bir vuruş çizerek mürekkep tablet kaleminden "akış" olarak görünür ve denetime eklendikten sonra tablet kalemi aracılığıyla, Pano'dan yapıştırıldıktan veya bir dosyadan yüklendikten sonra mürekkep görüntülenir. Dinamik olarak mürekkep işlemek için denetiminizin bir kullanması DynamicRenderer gerekir. Mürekkep statik olarak işlemek için veri toplamak, vuruşlar oluşturmak ve (denetimde mürekkep işler) eklemek içintylus olay yöntemlerini ( , ve ) geçersiz OnStylusDownOnStylusMoveOnStylusUpStylusPointInkPresenter kılmalısınız.
Bu konu aşağıdaki alt bölümlerden birini içerir:
Nasıl kullanılır:Tylus Noktası Verilerini Toplama ve Mürekkep Vuruşları Oluşturma
Nasıl edilir: Fareden Giriş Kabul Etmek için Denetiminizi Etkinleştirme
Nasıl kullanılır:Tylus Noktası Verilerini Toplama ve Mürekkep Vuruşları Oluşturma
Mürekkep vuruşlarını toplayan ve yöneten bir denetim oluşturmak için şunları yapın:
sınıfından veya Control sınıfından türetilen sınıflardan birini Control türetin, Label örneğin: .
using System; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Input.StylusPlugIns; using System.Windows.Controls; using System.Windows;class InkControl : Label {}sınıfına InkPresenter bir ekleyin ve özelliğini yeni olarak ContentInkPresenter ayarlayın.
InkPresenter ip; public InkControl() { // Add an InkPresenter for drawing. ip = new InkPresenter(); this.Content = ip; }yöntemini RootVisualDynamicRenderer çağırarak ve InkPresenter koleksiyonuna AttachVisualsDynamicRendererStylusPlugIns ekleyin. Bu, InkPresenter denetiminiz tarafındantylus noktası verileri toplanmış olarak mürekkep görüntülemeye olanak sağlar.
public InkControl() {// Add a dynamic renderer that // draws ink as it "flows" from the stylus. dr = new DynamicRenderer(); ip.AttachVisuals(dr.RootVisual, dr.DrawingAttributes); this.StylusPlugIns.Add(dr); }yöntemini geçersiz OnStylusDown kılın. Bu yöntemde, bir çağrısı iletylus'ları Capture yakalar. Stylus'ı yakalayarak, denetiminiz, denetim sınırları dışında bıraksa bile ve olayları almaya StylusMoveStylusUp devam eder. Bu kesinlikle zorunlu değildir, ancak iyi bir kullanıcı deneyimi için neredeyse her zaman istenen bir durumdur. Veri toplamak için StylusPointCollection yeni bir StylusPoint oluşturun. Son olarak, ilk veri StylusPoint kümelerini 'ye StylusPointCollection ekleyin.
protected override void OnStylusDown(StylusDownEventArgs e) { // Capture the stylus so all stylus input is routed to this control. Stylus.Capture(this); // Allocate memory for the StylusPointsCollection and // add the StylusPoints that have come in so far. stylusPoints = new StylusPointCollection(); StylusPointCollection eventPoints = e.GetStylusPoints(this, stylusPoints.Description); stylusPoints.Add(eventPoints); }yöntemini OnStylusMove geçersiz kılın ve StylusPoint verileri daha önce StylusPointCollection oluşturduğunuz nesnesine ekleyin.
protected override void OnStylusMove(StylusEventArgs e) { if (stylusPoints == null) { return; } // Add the StylusPoints that have come in since the // last call to OnStylusMove. StylusPointCollection newStylusPoints = e.GetStylusPoints(this, stylusPoints.Description); stylusPoints.Add(newStylusPoints); }yöntemini OnStylusUp geçersiz kılın ve verilerle Stroke yeni bir StylusPointCollection oluşturun. Oluşturduğunuz yeni Stroke ve sürüm stili yakalama StrokesInkPresenter koleksiyonuna ekleyin.
protected override void OnStylusUp(StylusEventArgs e) { if (stylusPoints == null) { return; } // Add the StylusPoints that have come in since the // last call to OnStylusMove. StylusPointCollection newStylusPoints = e.GetStylusPoints(this, stylusPoints.Description); stylusPoints.Add(newStylusPoints); // Create a new stroke from all the StylusPoints since OnStylusDown. Stroke stroke = new Stroke(stylusPoints); // Add the new stroke to the Strokes collection of the InkPresenter. ip.Strokes.Add(stroke); // Clear the StylusPointsCollection. stylusPoints = null; // Release stylus capture. Stylus.Capture(null); }
Nasıl edilir: Fareden Giriş Kabul Etmek için Denetiminizi Etkinleştirme
Önceki denetimi uygulamanıza ekler, çalıştırın ve fareyi giriş cihazı olarak kullanırsanız, vuruşların kalıcı olmadığını fark edersiniz. Giriş cihazı olarak fare kullanılırken vuruşları kalıcı yapmak için şunları yapın:
geçersiz kılın ve yeni bir Olay meydana geldiğinde farenin konumunu al ve noktası verilerini kullanarak bir oluşturun OnMouseLeftButtonDownStylusPointCollection ve StylusPoint 'ye StylusPointStylusPointCollection ekleyin.
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { base.OnMouseLeftButtonDown(e); // If a stylus generated this event, return. if (e.StylusDevice != null) { return; } // Start collecting the points. stylusPoints = new StylusPointCollection(); Point pt = e.GetPosition(this); stylusPoints.Add(new StylusPoint(pt.X, pt.Y)); }yöntemini geçersiz OnMouseMove kılın. Olay meydana geldiğinde farenin konumunu almak ve nokta verilerini StylusPoint kullanarak bir oluşturmak. daha StylusPoint önce StylusPointCollection oluşturduğunuz nesnesine ekleyin.
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); // If a stylus generated this event, return. if (e.StylusDevice != null) { return; } // Don't collect points unless the left mouse button // is down. if (e.LeftButton == MouseButtonState.Released || stylusPoints == null) { return; } Point pt = e.GetPosition(this); stylusPoints.Add(new StylusPoint(pt.X, pt.Y)); }yöntemini geçersiz OnMouseLeftButtonUp kılın. Verilerle Stroke yeni StylusPointCollection bir oluşturun ve oluşturduğunuz Stroke yeniyi Strokes koleksiyonuna InkPresenter ekleyin.
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); // If a stylus generated this event, return. if (e.StylusDevice != null) { return; } if (stylusPoints == null) { return; } Point pt = e.GetPosition(this); stylusPoints.Add(new StylusPoint(pt.X, pt.Y)); // Create a stroke and add it to the InkPresenter. Stroke stroke = new Stroke(stylusPoints); stroke.DrawingAttributes = dr.DrawingAttributes; ip.Strokes.Add(stroke); stylusPoints = null; }
Bir araya getirdi
Aşağıdaki örnek, kullanıcı fareyi veya kalemi kullandığında mürekkep toplayan özel bir denetimdir.
using System;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Input.StylusPlugIns;
using System.Windows.Controls;
using System.Windows;
// A control for managing ink input
class InkControl : Label
{
InkPresenter ip;
DynamicRenderer dr;
// The StylusPointsCollection that gathers points
// before Stroke from is created.
StylusPointCollection stylusPoints = null;
public InkControl()
{
// Add an InkPresenter for drawing.
ip = new InkPresenter();
this.Content = ip;
// Add a dynamic renderer that
// draws ink as it "flows" from the stylus.
dr = new DynamicRenderer();
ip.AttachVisuals(dr.RootVisual, dr.DrawingAttributes);
this.StylusPlugIns.Add(dr);
}
static InkControl()
{
// Allow ink to be drawn only within the bounds of the control.
Type owner = typeof(InkControl);
ClipToBoundsProperty.OverrideMetadata(owner,
new FrameworkPropertyMetadata(true));
}
protected override void OnStylusDown(StylusDownEventArgs e)
{
// Capture the stylus so all stylus input is routed to this control.
Stylus.Capture(this);
// Allocate memory for the StylusPointsCollection and
// add the StylusPoints that have come in so far.
stylusPoints = new StylusPointCollection();
StylusPointCollection eventPoints =
e.GetStylusPoints(this, stylusPoints.Description);
stylusPoints.Add(eventPoints);
}
protected override void OnStylusMove(StylusEventArgs e)
{
if (stylusPoints == null)
{
return;
}
// Add the StylusPoints that have come in since the
// last call to OnStylusMove.
StylusPointCollection newStylusPoints =
e.GetStylusPoints(this, stylusPoints.Description);
stylusPoints.Add(newStylusPoints);
}
protected override void OnStylusUp(StylusEventArgs e)
{
if (stylusPoints == null)
{
return;
}
// Add the StylusPoints that have come in since the
// last call to OnStylusMove.
StylusPointCollection newStylusPoints =
e.GetStylusPoints(this, stylusPoints.Description);
stylusPoints.Add(newStylusPoints);
// Create a new stroke from all the StylusPoints since OnStylusDown.
Stroke stroke = new Stroke(stylusPoints);
// Add the new stroke to the Strokes collection of the InkPresenter.
ip.Strokes.Add(stroke);
// Clear the StylusPointsCollection.
stylusPoints = null;
// Release stylus capture.
Stylus.Capture(null);
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
// If a stylus generated this event, return.
if (e.StylusDevice != null)
{
return;
}
// Start collecting the points.
stylusPoints = new StylusPointCollection();
Point pt = e.GetPosition(this);
stylusPoints.Add(new StylusPoint(pt.X, pt.Y));
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
// If a stylus generated this event, return.
if (e.StylusDevice != null)
{
return;
}
// Don't collect points unless the left mouse button
// is down.
if (e.LeftButton == MouseButtonState.Released ||
stylusPoints == null)
{
return;
}
Point pt = e.GetPosition(this);
stylusPoints.Add(new StylusPoint(pt.X, pt.Y));
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
// If a stylus generated this event, return.
if (e.StylusDevice != null)
{
return;
}
if (stylusPoints == null)
{
return;
}
Point pt = e.GetPosition(this);
stylusPoints.Add(new StylusPoint(pt.X, pt.Y));
// Create a stroke and add it to the InkPresenter.
Stroke stroke = new Stroke(stylusPoints);
stroke.DrawingAttributes = dr.DrawingAttributes;
ip.Strokes.Add(stroke);
stylusPoints = null;
}
}
Ek Eklentileri ve DynamicRenderers'ı Kullanma
InkCanvas gibi özel denetiminiz de özel ve ek StylusPlugIn nesnelere sahip DynamicRenderer olabilir. Bunları koleksiyona StylusPlugIns ekleyin. 'daki StylusPlugIn nesnelerin StylusPlugInCollection sırası, işlenecek mürekkep görünümünü etkiler. Tablet kaleminden DynamicRenderer mürekkep dynamicRenderer uzaklığında olan adlı ve adlı özel StylusPlugIn bir translatePlugin özeliniz olduğunu varsayalım. , içinde ilk ise ve ikinci ise, kullanıcı kalemi taşırken translatePluginStylusPlugInStylusPlugInCollectiondynamicRenderer "akan" mürekkep uzaklığı olur. birinci ve ikinci ise, kullanıcı kalemi kaldırana kadar mürekkep dynamicRenderertranslatePlugin kaydırmaz.
Sonuç
Stylus olay yöntemlerini geçersiz karak mürekkep toplayan ve işlayan bir denetim oluşturabilirsiniz. Kendi denetiminizi oluşturarak, kendi sınıflarınızı türeterek ve sınıflarını içine ekerek, dijital mürekkeple hayal edilebilir neredeyse tüm StylusPlugInStylusPlugInCollection davranışları uygulayabilirsiniz. Oluşturulan verilere erişebilirsiniz ve bu da size girişi özelleştirme ve ekranda uygulamanıza uygun şekilde StylusPointStylus işleme fırsatı sağlar. Verilere bu kadar düşük düzeyde erişiminiz olduğundan, mürekkep koleksiyonu gerçekleştirebilir ve bunu uygulamanıza StylusPoint en uygun performansla işebilirsiniz.