Je suis nouveau dans WPF, j'ai créé un nouveau UserControl MyUserControl.Emplacement UserControl dans WPF
Maintenant, je suis surpris: le UserContol n'a pas d'emplacement.
Comment puis-je lire (par code) myUserControl1. Location
dans le conteneur parent?
J'explique:
J'ai quelques points (UserControls) que l'utilisateur peut glisser dans un panneau. En fait, je ne suis pas sûr de quel genre de panneau ce sera ... Peut-être Grille.
Maintenant, ces points doivent être liés à une ligne. En fait, j'ai des propriétés Dot.Head
et Dot.Queue
(également des points) Donc, quand une tête ou une file d'attente est ajoutée, j'ai besoin de créer dinamiquement un lien (ligne) entre eux [A] ----- [B]. C'est pour cette ligne que je recherche les points de départ et de fin à définir.
contrôle XAML:
<UserControl x:Class="LinePlan.Stop"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="21" d:DesignWidth="80">
<Canvas>
<Path Fill="LightBlue" Width="16" Height="16">
<Path.Data>
<EllipseGeometry x:Name="Dot" Center="8,8"
RadiusX="4" RadiusY="4"/>
</Path.Data>
</Path>
<TextBlock x:Name="StopText" Text="Eiffel Tower" Canvas.Left="16"/>
</Canvas>
</UserControl>
code:
public partial class Stop : UserControl
{
private Stop head;
private Stop tail;
private LineGeometry headLine;
private LineGeometry queueLine;
public Stop()
{
InitializeComponent();
}
public Stop Head
{
get { return head; }
set
{
if (head != value)
{
head = value;
if (head == null)
{
if (headLine != null)
headLine = null;
}
else
{
headLine = new LineGeometry();
headLine.StartPoint = head.DotPosition;
headLine.EndPoint = this.DotPosition;
// ?? Add this line to the parent
}
}
}
}
public Stop Tail
{
get { return tail; }
set { tail = value; }
}
public Point DotPosition
{
get
{
double x = Canvas.GetLeft(this) + this.Dot.Center.X;
double y = Canvas.GetTop(this) + this.Dot.Center.Y;
return new Point(x, y);
}
set
{
Canvas.SetLeft(this, value.X - this.Dot.Center.X);
Canvas.SetTop(this, value.Y - this.Dot.Center.Y);
}
}
}
le mot "file d'attente" est un faux-ami * * ... Je pense que le mot que vous cherchez est "queue";) –
@ Thomas: bonne remarque – serhio