c# - The wpf controls dose't displaying on the canvas -
i inheritance canvas control , create custom canvas class this:
public class mycanvas:canvas { //this list contains shape visualcollection graphicslist; list<graphicsbase> clonegraphicslist; int c = 0; double deltax = 0; double deltay = 0; public mycanvas() :base() { graphicslist = new visualcollection(this); clonegraphicslist = new list<graphicsbase>(); } public visualcollection graphicslist { { return graphicslist; } set { graphicslist = value; } } protected override int visualchildrencount { { return graphicslist.count; } } protected override visual getvisualchild(int index) { if (index < 0 || index >= graphicslist.count) { throw new argumentoutofrangeexception("index"); } return graphicslist[index]; } public graphicsbase this[int index] { { if (index >= 0 && index < graphicslist.count) { return (graphicsbase)graphicslist[index]; } return null; } } public int count { { return graphicslist.count; } } }
and in xaml use code:
<window x:class="mynamespace.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:customcanvas="clr-namespace:mynamespace" xmlns:wpfruler="clr-namespace:orbifold.wpfruler;assembly=orbifold.wpfruler" title="printvarsdesigner" height="709" width="964" background="lightgray" grid.issharedsizescope="false" overridesdefaultstyle="false" windowstate="maximized" windowstartuplocation="centerscreen"> <customcanvas:mycanvas x:name="mycanvas" background="white" verticalalignment="top" width="895" height="1162"> </customcanvas:mycanvas> </window>
the controls does't appear after add visual screen or c# code add child canvas.
thanks advice.
inheriting wpf controls problematic least. wpf control's "lookless". say, control doesn't know how it's going presented. when control placed in window wpf looks corresponding controltemplate
specific control.
the problem inherited controls have no such template. if want display it, you'll have write 1 yourself, , that's not simple. can find example here, i'd recommend against it. use usercontrols instead.
Comments
Post a Comment