SL线如何连接图片的中心点
当前情况:
想要结果:
silverlight如何用线连接到图片的中心点(或贴着图片)呢?(线的坐标已知,图片的大小及坐标已知.)代码如何实现呢?
[解决办法]
妹子的贴友情支持下,坐等大拿们解决啊
[解决办法]
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="450" >
<Canvas >
<Image x:Name="image1" Stretch="None" Source="无标题.png" Canvas.Left="35" Canvas.Top="46"/>
<Line x:Name="line1" Stroke="Green" StrokeThickness="2" X1="160" Y1="290" X2="0" Y2="0"/>
<Button Content="Button" Canvas.Left="242" Canvas.Top="71" Width="75" Click="Button_Click"/>
</Canvas>
</Window>
using System;
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Double x = Canvas.GetLeft(image1);
Double y = Canvas.GetTop(image1);
//图片大小120*120
x += 120 / 2;
y += 120 / 2;
line1.X1 = x;
line1.Y1 = y;
}
}
}