c# - Custom control does not exist in the namespace? -


i've been interested in wpf bindings in c# , tried bind control mouse position, after getting frustrating "the name "[control]" not exist in namespace "clr-namespace:[namespace]" every time pasted xaml code editor decided wasn't worth time investigate quirk.

now attempting implement binded arc drawing example stack overflow , getting same eror again. (all code short runnable example can found there)

so i've combed through stack overflow solution issue (it seems rather widespread) appear sporadic , inexpiable workarounds , fixes.


  1. this question says

if nothing else possible, comment lines use namespace, rebuild, , build full project again.

i tried rebuilding project, reopening visual studio. nothing helped. commented xaml, rebuilt project, uncommented xaml , worked! strange issue.

  1. this one said set project release mode , answer-er on same question said define assembly: (xmlns:local="clr-namespace:musicplayer.controls;assembly=musicplayer") did not work me either.
  2. this person recommended changing build target platform (x86 - x64)

i've tried pretty of these solution no avail. resharper seems know arc class exists in namespace assigned local, visual studio not.

<local:arc center="{binding path=previousmousepositionpixels}"           stroke="white"           strokedasharray="4 4"          snapstodevicepixels="true"          startangle="0"           endangle="{binding path=deltaangle}"           smallangle="true"          radius="40"/> 

using system; using system.collections.generic; using system.windows; using system.windows.documents; using system.windows.media; using system.windows.shapes;  public sealed class arc : shape {     public point center     {         { return (point)getvalue(centerproperty); }         set { setvalue(centerproperty, value); }     }      // using dependencyproperty backing store center.  enables animation, styling, binding, etc...     public static readonly dependencyproperty centerproperty =         dependencyproperty.register("center", typeof(point), typeof(arc)         , new frameworkpropertymetadata(new point(0, 0), frameworkpropertymetadataoptions.affectsrender));       public double startangle     {         { return (double)getvalue(startangleproperty); }         set { setvalue(startangleproperty, value); }     }      // using dependencyproperty backing store startangle.  enables animation, styling, binding, etc...     public static readonly dependencyproperty startangleproperty =         dependencyproperty.register("startangle", typeof(double), typeof(arc)         , new frameworkpropertymetadata(0.0, frameworkpropertymetadataoptions.affectsrender));      public double endangle     {         { return (double)getvalue(endangleproperty); }         set { setvalue(endangleproperty, value); }     }      // using dependencyproperty backing store endangle.  enables animation, styling, binding, etc...     public static readonly dependencyproperty endangleproperty =         dependencyproperty.register("endangle", typeof(double), typeof(arc)         , new frameworkpropertymetadata(math.pi/2.0, frameworkpropertymetadataoptions.affectsrender));      public double radius     {         { return (double)getvalue(radiusproperty); }         set { setvalue(radiusproperty, value); }     }      // using dependencyproperty backing store radius.  enables animation, styling, binding, etc...     public static readonly dependencyproperty radiusproperty =         dependencyproperty.register("radius", typeof(double), typeof(arc)         , new frameworkpropertymetadata(10.0, frameworkpropertymetadataoptions.affectsrender));        public bool smallangle     {         { return (bool)getvalue(smallangleproperty); }         set { setvalue(smallangleproperty, value); }     }      // using dependencyproperty backing store smallangle.  enables animation, styling, binding, etc...     public static readonly dependencyproperty smallangleproperty =         dependencyproperty.register("smallangle", typeof(bool), typeof(arc)         , new frameworkpropertymetadata(false, frameworkpropertymetadataoptions.affectsrender));       static arc()     {         defaultstylekeyproperty.overridemetadata(typeof(arc), new frameworkpropertymetadata(typeof(arc)));     }      protected override geometry defininggeometry     {                 {              var a0 = startangle < 0 ? startangle + 2 * math.pi : startangle;             var a1 = endangle < 0 ? endangle + 2 * math.pi : endangle;              if (a1<a0)             {                 a1 += math.pi * 2;             }              sweepdirection d = sweepdirection.counterclockwise;             bool large;              if (smallangle)             {                 large = false;                 double t = a1;                 if ((a1-a0)>math.pi)                 {                     d = sweepdirection.counterclockwise;                 }                 else                 {                     d = sweepdirection.clockwise;                 }               }else{                 large = (math.abs(a1 - a0) < math.pi);             }              point p0 = center + new vector(math.cos(a0), math.sin(a0)) * radius;             point p1 = center + new vector(math.cos(a1), math.sin(a1)) * radius;               list<pathsegment> segments = new list<pathsegment>(1);             segments.add(new arcsegment(p1, new size(radius, radius), 0.0, large, d, true));              list<pathfigure> figures = new list<pathfigure>(1);             pathfigure pf = new pathfigure(p0, segments, true);             pf.isclosed = false;             figures.add(pf);              geometry g = new pathgeometry(figures, fillrule.evenodd, null);             return g;         }     } } 

define arc inside namespace suggested robcroll. check below code, have included in arc_learning namespace referred in xaml local.

    <window x:class="arc_learning.mainwindow"         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"         xmlns:local="clr-namespace:arc_learning"         mc:ignorable="d"         title="mainwindow" height="350" width="525">     <grid>         <local:arc              stroke="white"           strokedasharray="4 4"          snapstodevicepixels="true"          startangle="0"           endangle="{binding path=deltaangle}"           smallangle="true"          radius="40"/>     </grid> </window>      using system; using system.collections.generic; using system.windows; using system.windows.documents; using system.windows.media; using system.windows.shapes;  namespace arc_learning {     public sealed class arc : shape     {         public point center         {             { return (point)getvalue(centerproperty); }             set { setvalue(centerproperty, value); }         }          // using dependencyproperty backing store center.  enables animation, styling, binding, etc...         public static readonly dependencyproperty centerproperty =             dependencyproperty.register("center", typeof(point), typeof(arc)             , new frameworkpropertymetadata(new point(0, 0), frameworkpropertymetadataoptions.affectsrender));           public double startangle         {             { return (double)getvalue(startangleproperty); }             set { setvalue(startangleproperty, value); }         }          // using dependencyproperty backing store startangle.  enables animation, styling, binding, etc...         public static readonly dependencyproperty startangleproperty =             dependencyproperty.register("startangle", typeof(double), typeof(arc)             , new frameworkpropertymetadata(0.0, frameworkpropertymetadataoptions.affectsrender));          public double endangle         {             { return (double)getvalue(endangleproperty); }             set { setvalue(endangleproperty, value); }         }          // using dependencyproperty backing store endangle.  enables animation, styling, binding, etc...         public static readonly dependencyproperty endangleproperty =             dependencyproperty.register("endangle", typeof(double), typeof(arc)             , new frameworkpropertymetadata(math.pi / 2.0, frameworkpropertymetadataoptions.affectsrender));          public double radius         {             { return (double)getvalue(radiusproperty); }             set { setvalue(radiusproperty, value); }         }          // using dependencyproperty backing store radius.  enables animation, styling, binding, etc...         public static readonly dependencyproperty radiusproperty =             dependencyproperty.register("radius", typeof(double), typeof(arc)             , new frameworkpropertymetadata(10.0, frameworkpropertymetadataoptions.affectsrender));            public bool smallangle         {             { return (bool)getvalue(smallangleproperty); }             set { setvalue(smallangleproperty, value); }         }          // using dependencyproperty backing store smallangle.  enables animation, styling, binding, etc...         public static readonly dependencyproperty smallangleproperty =             dependencyproperty.register("smallangle", typeof(bool), typeof(arc)             , new frameworkpropertymetadata(false, frameworkpropertymetadataoptions.affectsrender));           static arc()         {             defaultstylekeyproperty.overridemetadata(typeof(arc), new frameworkpropertymetadata(typeof(arc)));         }          protected override geometry defininggeometry         {                         {                  var a0 = startangle < 0 ? startangle + 2 * math.pi : startangle;                 var a1 = endangle < 0 ? endangle + 2 * math.pi : endangle;                  if (a1 < a0)                 {                     a1 += math.pi * 2;                 }                  sweepdirection d = sweepdirection.counterclockwise;                 bool large;                  if (smallangle)                 {                     large = false;                     double t = a1;                     if ((a1 - a0) > math.pi)                     {                         d = sweepdirection.counterclockwise;                     }                     else                     {                         d = sweepdirection.clockwise;                     }                   }                 else {                     large = (math.abs(a1 - a0) < math.pi);                 }                  point p0 = center + new vector(math.cos(a0), math.sin(a0)) * radius;                 point p1 = center + new vector(math.cos(a1), math.sin(a1)) * radius;                   list<pathsegment> segments = new list<pathsegment>(1);                 segments.add(new arcsegment(p1, new size(radius, radius), 0.0, large, d, true));                  list<pathfigure> figures = new list<pathfigure>(1);                 pathfigure pf = new pathfigure(p0, segments, true);                 pf.isclosed = false;                 figures.add(pf);                  geometry g = new pathgeometry(figures, fillrule.evenodd, null);                 return g;             }         }     } } 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -