社区
WPF/Silverlight
帖子详情
如何获取TextBlock 在Canvas中的位置
cfsjjjj
2010-08-06 10:24:12
TextBlock tx=new TextBlock ();
tx.RenderTransform = new TranslateTransform(){ X =100, Y = 200};
现在这么能获取x 和y的值啊!
...全文
170
3
打赏
收藏
如何获取TextBlock 在Canvas中的位置
TextBlock tx=new TextBlock (); tx.RenderTransform = new TranslateTransform(){ X =100, Y = 200}; 现在这么能获取x 和y的值啊!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
dui_cky
2010-08-07
打赏
举报
回复
使用offset获取位置:
GeneralTransform mygt = this.TransformToVisual(Application.Current.RootVisual as UIElement);
Point offset = mygt.Transform(new Point(0, 0));
double controlTop = offset.Y;
double controlLeft = offset.X;
//Application.Current.RootVisual 是你相对 的控件
或者
或者转换为 MatrixTransform
MatrixTransform transform = source.TransformToVisual(container) as MatrixTransform;
其中 source 为 UIElement ,为要取得坐标的控件;
container 为 UIElement ,为 source 的参照物,一般可以取上级容器。
得到 transform.Matrix.OffsetX 、transform.Matrix.OffsetY
老Key
2010-08-07
打赏
举报
回复
[Quote=引用 2 楼 dui_cky 的回复:]
使用offset获取位置:
GeneralTransform mygt = this.TransformToVisual(Application.Current.RootVisual as UIElement);
Point offset = mygt.Transform(new Point(0, 0));
double controlTop = offset.Y;
double cont……
[/Quote]嗯,,说的挺不错的。。
cfsjjjj
2010-08-06
打赏
举报
回复
一天了 怎么都没人啊!!!
在
Canvas
中
使控件居
中
//在将
TextBlock
添加到
Canvas
前
获取
它的实际尺寸
TextBlock
label = new
TextBlock
; label.Text = "It is a test"; label.Measure(new Size(double.PositiveInfinity, double.Po...
WPF
中
的
TextBlock
隐藏边框
TextBlock
默认是有边框的,显示效果如下:有一个淡蓝色的边框围绕着 如果需要隐藏这个边框,则只需要在代码
中
加上以下代码即可: BorderBrush="{x:Null}" BorderThickness="0" <...
WPF
获取
TextBlock
或者TextBox的内容像素宽度(Width)
1、首先
获取
DPI,系统的显示缩放影响Width dpiInfo = VisualTreeHelper.GetDpi(this); 2、根据文字的字体、大小等等因素
获取
像素宽度 var formattedText = new FormattedText("文本值", System.Globalization....
WPF:
TextBlock
和 Label文字垂直显示
简述 制作曲线时,Y轴标签需要垂直显示。只需将
TextBlock
或 Label 的Layout旋转90...
TextBlock
x:Name="TbYAxis"
Canvas
.Left="10"
Canvas
.Top="50" FontSize="20" Foreground="White" Text="Y轴"> <Te...
c# WPF如何实现滚动显示的
TextBlock
这篇文章主要介绍了c# WPF如何实现滚动显示的
TextBlock
,帮助大家更... 在我们使用
TextBlock
进行数据显示时,经常会遇到这样一种情况就是
TextBlock
的文字内容太多,如果全部显示的话会占据大量的界面,这是我们就会只
WPF/Silverlight
8,735
社区成员
12,029
社区内容
发帖
与我相关
我的任务
WPF/Silverlight
WPF/Silverlight相关讨论
复制链接
扫一扫
分享
社区描述
WPF/Silverlight相关讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章