Silverlight 动态控件不显示
我有一个简单的控件,带有代码来添加一些路径。当我将控件添加到控件画布时,什么也没有显示。为了确保我没有发疯,我调试了代码,并创建了一个 XAML 等效项,并将其放置在我的控件应该显示的一侧。我尝试更改 z-index 和各种顶部/左侧组合来尝试显示我的路径,但没有运气。我的控件位于 Canvas 子集合中,但它们就是不想出现!这是我的代码
for (int i = 0; i < 4; i++)
{
SolidColorBrush brush = new SolidColorBrush();
brush.Color = GetColor();
path = new Path();
path.Data = getData(i);
path.Name = i.ToString();
path.SetValue(Canvas.LeftProperty, 150.0);
path.SetValue(Canvas.TopProperty, 150.0);
path.SetValue(Canvas.ZIndexProperty, 1000);
path.Fill = brush;
mainLayout.Children.Add(path);
}
,这是 XAML。其中硬编码的路径是我通过单步执行代码创建的路径。
<Canvas Name="mainLayout">
<Path Name="Path5" Fill="Red" Canvas.Left="450" Canvas.Top="150" Data="M 0,-100 A 100,100 0.628332123128715 0 1 58.7796248729471,-80.9009004881628 L 0,0" ></Path>
<Path Name="Path6" Fill="Green" Canvas.Left="450" Canvas.Top="150" Data="M 58.7796248729471,-80.9009004881628 A 100,100 0.559576083957105 0 1 92.7589501245075,-37.3601013355041 L 0,0" ></Path>
<Path Name="Path7" Fill="Blue" Canvas.Left="450" Canvas.Top="150" Data="M 92.7589501245075,-37.3601013355041 A 100,100 3.11153310318617 0 1 -91.5941871397306,40.1310961999795 L 0,0" ></Path>
<Path Name="Path8" Fill="Yellow" Canvas.Left="450" Canvas.Top="150" Data="M -91.5941871397306,40.1310961999795 A 100,100 1.98374399690759 0 1 -1.1330996904646E-13,-100 L 0,0" ></Path>
</Canvas>
当我运行所有内容时,只显示硬编码路径。
I have a simple control with code to add some paths. When I add my control to the control canvas, nothing shows up. To make sure that I wasn't crazy, I debugged through the code, and created a XAML equivalent and placed it off to the side of where my control should be showing up. I've tried changing the z-index and various Top/Left combination's to try an get my paths to show but no luck. My controls are in the Canvas children collection, but they just don't want to turn up! Here's my code
for (int i = 0; i < 4; i++)
{
SolidColorBrush brush = new SolidColorBrush();
brush.Color = GetColor();
path = new Path();
path.Data = getData(i);
path.Name = i.ToString();
path.SetValue(Canvas.LeftProperty, 150.0);
path.SetValue(Canvas.TopProperty, 150.0);
path.SetValue(Canvas.ZIndexProperty, 1000);
path.Fill = brush;
mainLayout.Children.Add(path);
}
And heres the XAML. The paths hard coded in there are the paths I created by stepping through the code.
<Canvas Name="mainLayout">
<Path Name="Path5" Fill="Red" Canvas.Left="450" Canvas.Top="150" Data="M 0,-100 A 100,100 0.628332123128715 0 1 58.7796248729471,-80.9009004881628 L 0,0" ></Path>
<Path Name="Path6" Fill="Green" Canvas.Left="450" Canvas.Top="150" Data="M 58.7796248729471,-80.9009004881628 A 100,100 0.559576083957105 0 1 92.7589501245075,-37.3601013355041 L 0,0" ></Path>
<Path Name="Path7" Fill="Blue" Canvas.Left="450" Canvas.Top="150" Data="M 92.7589501245075,-37.3601013355041 A 100,100 3.11153310318617 0 1 -91.5941871397306,40.1310961999795 L 0,0" ></Path>
<Path Name="Path8" Fill="Yellow" Canvas.Left="450" Canvas.Top="150" Data="M -91.5941871397306,40.1310961999795 A 100,100 1.98374399690759 0 1 -1.1330996904646E-13,-100 L 0,0" ></Path>
</Canvas>
When I run everything, only the hard coded paths show up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个简单的问题,当您单步执行时, getDate(i) 是否返回路径,并且 getColor() 是否返回除 color.transparent 之外的任何其他内容
Two quick questions, when you stepped through it, did getDate(i) return a path, and did getColor() return anything else except colors.transparent