silverlight自定义标签的问题

yataoding 2009-09-09 02:26:51
Page.xaml:
<UserControl x:Class="chart.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:chart;assembly=chart"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Line X1="100" X2="300" Y1="100" Y2="300" Stroke="Red" StrokeThickness="3"></Line>
<custom:Chart></custom:Chart> 些处引用自定义标签
</Grid>
</UserControl>

Chart.cs
public class Chart : ContentControl
{
public Chart()
{
// Create a Line
Line redLine = new Line();
redLine.X1 = 50;
redLine.Y1 = 50;
redLine.X2 = 200;
redLine.Y2 = 200;

// Create a red Brush
SolidColorBrush redBrush = new SolidColorBrush();
redBrush.Color = Colors.Red;

// Set Line's width and color
redLine.StrokeThickness = 4;
redLine.Stroke = redBrush;

// Add line to the Grid.
//LayoutRoot.Children.Add(redLine); (LayoutRoot是Page里的,所以这时用不了)
}
}

为什么<Line X1="100" X2="300" Y1="100" Y2="300" Stroke="Red" StrokeThickness="3"></Line>只要写到xaml中就可以了,而我自定义的标签<custom:Chart></custom:Chart>就显示不出来呢?
我要怎么才能把自定义的标签也能像系统自带的一样显示出来呢。
...全文
137 6 打赏 收藏 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yataoding 2009-11-16
  • 打赏
  • 举报
回复
Chart类继承Panel就可以了。这个才是关键,看到自己以前发的帖子,顺便提一下。
skiasky 2009-09-10
  • 打赏
  • 举报
回复
<UserControl x:Class="chart.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:custom="clr-namespace:chart;assembly=chart"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Canvas>
<Line X1="100" X2="300" Y1="100" Y2="300" Stroke="Red" StrokeThickness="3"> </Line>
<custom:Chart> </custom:Chart>
</Canvas>
</Grid>
</UserControl>


line应该画在支持绝对位置的canvas面板里面。
zhuzhi 2009-09-10
  • 打赏
  • 举报
回复
看没懂你说的“显示不出来”是什么意思,是说这个标签在编辑的时候能够自动弹出,还是说运行的时候看不到呢
jv9 2009-09-09
  • 打赏
  • 举报
回复
<custom:Chart>是什么?定义的是一个容器控件么?
yataoding 2009-09-09
  • 打赏
  • 举报
回复
我要实现如下功能
<custom:Axis O_X=100 O_Y=100>
<custom:Axis_X Wid=100></custom:Axis_X>
<custom:Axis_Y Wid=50></custom:Axis_X>
</custom:Axis>
这后就会画出一个以(100,100)为原点,X轴长100,Y轴长50的坐标轴。(当然这只是个开始,以后还要完善好多功能)
有没有做过类似东西的,提供个思路。
malin2670372 2009-09-09
  • 打赏
  • 举报
回复
<custom:Chart> 要设置宽,高,内容 属性吧。。不然是空的!

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧