c# - WPF richTextBox cant identify as UIElement -


i have following code attaches adorners uielements have on canvas.

private void slidecanvas_previewmouseleftbuttondown(object sender, mousebuttoneventargs e) {   {                 selected = false;                 if (selectedelement != null)                 {                     alayer.remove(alayer.getadorners(selectedelement)[0]);                     selectedelement = null;                 }             }              if (e.source != slidecanvas)             {                 _isdown = true;                 _startpoint = e.getposition(slidecanvas);                  selectedelement = e.source uielement;                  _originalleft = canvas.getleft(selectedelement);                 _originaltop = canvas.gettop(selectedelement);                  alayer = adornerlayer.getadornerlayer(selectedelement);                 alayer.add(new resizingadorner(selectedelement));                 selected = true;                 e.handled = true;             } } 

for reason though when click on richtextbox during runtime program crashes richtextbox not found e.source uielement.

selectedelement null.

can tell me why , give me work around please?

apparently e.source document of richtextbox clicked on. flowdocument, not derived uielement.

you may access richtextbox flowdocument's parent property.

if (e.source flowdocument) {     selectedelement = ((flowdocument)e.source).parent uielement; } else {     selectedelement = e.source uielement; } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -