Click here to Skip to main content
15,886,077 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have this cute little astronomy program that was supposed to be a week of coding for my own pleasure; which now have become a nightmare!

I simply have a piece of XAML:
<Ellipse Canvas.Left="15.38676905655"
                Canvas.Top="11.784944134632"
                Height="5px" Width="5px" Fill="Red"
                Panel.ZIndex="-800"
                Cursor="Hand">
        <Ellipse.RenderTransform>
            <TranslateTransform X="-2" Y="-2" />
        </Ellipse.RenderTransform>
        <Ellipse.ToolTip>
            <ToolTip>
                <StackPanel>
                    <TextBlock>Proxima Centauri</TextBlock>
                    <TextBlock>-1,538676906;-1,178494413;-3,752088504</TextBlock>
                </StackPanel>
            </ToolTip>
        </Ellipse.ToolTip>
    </Ellipse>

That I want to add during runtime to the canvas "starfield". I'm getting the data from a database, (I have no intention of typing in 45'000 stars to create a starmap manually), I however have met some issues.

Adding:
<Ellipse Canvas.Left="15.38676905655" Canvas.Top="11.784944134632" Height="5px" Width="5px" Fill="Red" Panel.ZIndex="-800" Cursor="Hand"/>

Is no problem, I got 3 different ways of doing that. But its the things nested inside the "Ellipse" that's the problem.

anyone got a fix for this??

thank you!

-Frank
Posted

What about adding all of the Ellipse programatically instead of in a xaml file? Then you can just fill in the details from the database.

C#
var tool = new StackPanel();
tool.Children.Add(new TextBlock() { Text = "Proxima Centauri" });
tool.Children.Add(new TextBlock() { Text = "-1,538676906;-1,178494413;-3,752088504" });

var star = new Ellipse
{
    Height = 5,
    Width = 5,
    Fill = Brushes.Red,
    RenderTransform = new TranslateTransform(-2, -2),
    ToolTip = tool,
    Cursor = Cursors.Hand
};
star.SetValue(Canvas.LeftProperty, 15.38676905655);
star.SetValue(Canvas.TopProperty, 11.784944134632);
star.SetValue(Canvas.ZIndexProperty, -800);

parentCanvas.Children.Add(star);
 
Share this answer
 
Comments
Frank R. Haugen 12-Jun-12 16:14pm    
I love you! That worked like a charm!!!
Steve Maier 12-Jun-12 16:17pm    
Thanks Frank. Doing WPF since it was a CTP does have advantages.
You can also do things in XAML, and there are cases where this is better. Maybe not in this case, but some things just do not work well programatically:

XML
string Xaml= @"<SolidColorBrush xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Color="AliceBlue"/>;
          StringReader stringReader = new StringReader(Xaml);
          System.Xml.XmlReader xmlReader = new System.Xml.XmlTextReader(stringReader);
          Brush rslt = XamlReader.Load(xmlReader) as Brush;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900