The Artima Developer Community
Sponsored Link

.NET Buzz Forum
WPF: Element innerhalb eines Canvas per Sourcecode positionieren

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
-

Posts: 1524
Nickname: nitronic
Registered: Jul, 2006

Norbert Eder works as a software architect.
WPF: Element innerhalb eines Canvas per Sourcecode positionieren Posted: Nov 16, 2007 6:14 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by -.
Original Post: WPF: Element innerhalb eines Canvas per Sourcecode positionieren
Feed Title: Norbert Eder - Living .NET
Feed URL: http://feeds.feedburner.com/NorbertEder-Livingnet
Feed Description: Copyright (c)2005, 2006 by Norbert Eder
Latest .NET Buzz Posts
Latest .NET Buzz Posts by -
Latest Posts From Norbert Eder - Living .NET

Advertisement
Von den Windows-Forms ist man ja noch die Eigenschaft Location gewohnt. Diese gibt es bei WPF nicht mehr, stattdessen muss man einen anderen Weg gehen.

Per XAML wird ein Element in einem Canvas recht einfach exakt positioniert:
<Canvas x:Name="LayoutRoot" Background="Yellow">
    <ListBox 
        Width="100" 
        Height="100" 
        Canvas.Left="352" 
        Canvas.Top="192" 
        IsSynchronizedWithCurrentItem="True"/>
</Canvas>

Doch wie wird das per Code gemacht? Eigentlich auch nicht wirklich schwieriger, man muss eben nur wissen wie:
Canvas canvas=new Canvas();
canvas.Background=Brushes.Yellow;

ListBox lbx=new ListBox();
lbx.Width=100;
lbx.Height=100;
lbx.IsSynchronizedWithCurrentItem=true;
Canvas.SetLeft(lbx,352);
Canvas.SetTop(lbx,192);
canvas.Children.Add(lbx);

An vielen Stellen ist also dann doch ein Umdenken notwendig und ich ertappe mich anscheinend selbst noch oft bei meinem alten Denkschema.

Read: WPF: Element innerhalb eines Canvas per Sourcecode positionieren

Topic: Code-Dokumentation einfach gemacht! Previous Topic   Next Topic Topic: Ruby, Rails, Rails Plugins, Mac OS X, JavaScript

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use