views:

39

answers:

0

In my project there is a library bar which is created by the Element Menu by a click event. the element menu is located at a grid, which is located at the window. (see XAML data) While moving the tagged element menu/grid i want the library bar to move over the surface as well. I'm not really sure how to do it: do you think i need to use the canvas object? Shall the canvas directly be used in the structure or can i use it at runtime? Could the problem be solved by margin? I hope someone could help me.

My code:

    private void TV_Handy1_Moved(object sender, TagVisualizerEventArgs e)
    {
        TagVisualization tv1 = sender as TagVisualization;

        TagVisualizer tv = this.Visualizer;
        ScatterView sv = tv.Content as ScatterView;
        //alle aktuellen Objekte
        IEnumerator en = sv.Items.SourceCollection.GetEnumerator();
        //Grid bekommen, wo ElementMenü drauf liegt
        Grid g = tv.Parent as Grid;
        //Window, wo alles drauf liegt (Menü und neues LB)
        SurfaceWindow1 w = g.Parent as SurfaceWindow1;

        /*HauptCanvas für ander Canvas
        Canvas mainCan = new Canvas();
        mainCan.Height = w.ActualHeight;
        mainCan.Width = w.ActualWidth;
        mainCan.Children.Add(sv);

        //UnterCanvas für Menü
        Canvas menuCan = new Canvas();
        menuCan.Height = g.ActualHeight;
        menuCan.Width = g.ActualWidth;
        menuCan.Children.Add(g);

        //UnterCanvas für LB
        Canvas lbCan = new Canvas();
        */
        //Position vom Menü
        GeneralTransform gt = g.TransformToVisual(w); //Application.Current.RootVisual

        Point topLeft = gt.Transform(new Point(0, 0));
        Point topRight = gt.Transform(new Point(g.RenderSize.Width, 0));
        Point bottomLeft = gt.Transform(new Point(0, g.RenderSize.Height));
        Point bottomRight = gt.Transform(new Point(g.RenderSize.Width, g.RenderSize.Height));
        Point offset = gt.Transform(new Point(0,0));
        double menuTop = offset.X;
        double menuLeft = offset.Y;

        //aktuelles LB holen
        while (en.MoveNext())
        {
            Object temp = en.Current;
            if (temp is LibraryBar)
            {
                //TODO: TEst welches LB offen
                LibraryBar cLB = temp as LibraryBar;
                //Pos zuweisen
                Thickness t = new Thickness(0);
                t.Left = menuTop;
                t.Right = menuLeft;
                cLB.Margin= t;

                /*lbCan.Height = cLB.ActualHeight;
                lbCan.Width = cLB.ActualWidth;
                lbCan.SetTop(cLB,100);
                lbCan.SetLeft(cLB,100);
                lbCan.Children.Add(cLB);

                mainCan.Children.Add(menuCan);
                mainCan.Children.Add(lbCan);
                w.Content = mainCan;
                w.Show();
                */

                //an Grid neues LB binden -> folgt dann hoffentlich automatisch
                //g.Children.Add(cLB);
            }
        }

the xaml file:

<Grid Name="MenuGrid" Grid.Row="2" Height="350" Width="500">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="55*" />
        <ColumnDefinition Width="65*" />
    </Grid.ColumnDefinitions>

        <s:ElementMenu 
        Name="MainMenu"
        s:SurfaceMenu.ContactLeave="MainMenu_ContactChanged"
        ActivationMode="AlwaysActive"
        ActivationHost="{Binding ElementName=MenuGrid}"  Width="200" Height="300" IsSubmenuOpen="True" s:SurfaceDragDrop.Drop="OnDrop"
        AllowDrop="True" Grid.ColumnSpan="2" Margin="147,-24,153,74" Background="#9B23B6E2">

        <s:ElementMenuItem Header="Kontakte"> 
        </s:ElementMenuItem>
            <s:ElementMenuItem Header="Musik">
        </s:ElementMenuItem>
        <s:ElementMenuItem Header="Videos">   
        </s:ElementMenuItem>
            <s:ElementMenuItem Header="Bilder" AllowDrop="True"  IsEnabled="True" s:ElementMenuItem.Click ="ElementMenuItem_Click" Background="Aqua" >
            </s:ElementMenuItem>    
    </s:ElementMenu>
</Grid>

Thanks for your help.