0
I 상속을 표시 dose't 나는이 같은 내 사용자 지정 캔버스 클래스를 만들 :WPF 컨트롤 캔버스 컨트롤에서 캔버스에
<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>
:
public class MyCanvas:Canvas
{
//this list will contains all 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
{
get
{
return graphicsList;
}
set
{
graphicsList = value;
}
}
protected override int VisualChildrenCount
{
get
{
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]
{
get
{
if (index >= 0 && index < GraphicsList.Count)
{
return (GraphicsBase)GraphicsList[index];
}
return null;
}
}
public int Count
{
get
{
return GraphicsList.Count;
}
}
}
및 XAML에서
이 코드를 사용 컨트롤은 시각적 인 화면이나 C# 코드에서 아이를 캔버스에 추가하여 추가 한 후에 나타나지 않습니다.어떤 조언을 주셔서 감사합니다.
훌륭한 반응과 참고 자료. 고맙습니다! –