Select to view content in your preferred language

How to create a childwindow and show it at a position (example top right)

2857
1
02-29-2012 09:14 AM
SerajDhaliwal
Deactivated User
Hello, need help with positioning of dialog window on silverlight viewer.....

Xaml is below, simple dialog window

[INDENT]<UserControl x:Class="HelloWorld.AddIns.TimeSliderPopup"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
           Width="263" Height="207"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" HorizontalAlignment="Right" VerticalAlignment="Top" OpacityMask="NavajoWhite" Opacity="100">
    <Grid x:Name="LayoutRoot" Margin="5" Width="Auto" Height="Auto">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="93*" />
            <ColumnDefinition Width="285*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="32*" />
            <RowDefinition Height="38*" />
            <RowDefinition Height="156*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <sdk:Label Content="[SITETITLE]" Name="lblSiteTitle" Grid.ColumnSpan="2" />
        <sdk:Label Grid.Row="1" Name="label2" Content="POC" />
        <sdk:Label Grid.Row="2" Name="label3" Content="EVENTS" />

        <Button x:Name="CloseButton" Content="Close" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="3" Grid.Column="1" />
    </Grid>
</UserControl>[/INDENT]

Code to open and show the dialog:

[INDENT]                testDialog = new TestDialog();
                MapApplication.Current.ShowWindow("Test Dialog", testDialog);
[/INDENT]

The dialog always shows up in the middle of the screen....  Event tried to set the HorizontalAlignment and VerticalAlignment....

Any help would be appreciated.
0 Kudos
1 Reply
SerajDhaliwal
Deactivated User
This has been resolved - i confused childwindow (from my C# days) to floatingwindow....  Below is step by step

1/ In your add-in make sure following references are available (not all may be used but this is what my project showing; will iron out what is required or not later on):
ESRI.ArcGIS.Client
ESRI.ArcGIS.Client.Application.Controls
ESRI.ArcGIS.Client.Extensibility
ESRI.ArcGIS.Client.Toolkit

2/ Create a UserControl (below is a simple user control)
<UserControl x:Class="HelloWorld.AddIns.TimeSliderPopup"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
           Width="263" Height="207"
           xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" HorizontalAlignment="Right" VerticalAlignment="Top" OpacityMask="NavajoWhite" Opacity="100">
    <Grid x:Name="LayoutRoot" Margin="5" Width="Auto" Height="Auto" Background="Transparent">
            <StackPanel Orientation="Vertical" Canvas.Top="5" Canvas.Left="20">
                <sdk:Label Content="[SITETITLE]" Name="lblSiteTitle" Grid.ColumnSpan="2" />
                <sdk:Label Grid.Row="1" Name="label2" Content="POC" />
                <sdk:Label Grid.Row="2" Name="label3" Content="EVENTS" />

                <Button x:Name="CloseButton" Content="Close" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="3" Grid.Column="1" />

            </StackPanel>
    </Grid>
</UserControl>

3/ Code-behind for the user-control is simple (no additional code - just default).

4/ To create and use the control as a floating window ....
- Add following using statements
using ESRI.ArcGIS.Client.Application.Controls;
using System.ComponentModel.Composition;

- Define some global properties
        private PopupDialog popupDialog;
        private FloatingWindow window;

- Create the dialog and floating window (this is in the MouseRightButtonDown event handler for a graphic)
            // Get the Graphic object that was clicked on.
            ESRI.ArcGIS.Client.Graphic pt = (ESRI.ArcGIS.Client.Graphic)sender;

            // check and create popup if required
            if (popupDialog == null)
            {
                window = new FloatingWindow()
                {
                    HorizontalAlignment = HorizontalAlignment.Right,
                    VerticalAlignment = VerticalAlignment.Top
                };

                popupDialog = new TimeSliderPopup()
                {
                };

                popupDialog.CloseButton.Click += new RoutedEventHandler(popupDialogCloseButton_Click);

                window.Content = popupDialog;
                window.Show();
            }

            // set attribute into popup dialog using [pt.attributes["SiteInfo"].ToString();
            popupDialog.lblSiteTitle.Content = pt.Attributes["StateName"].ToString();

- Define CloseButton_Click event

        void popupDialogCloseButton_Click(object sender, RoutedEventArgs e)
        {
            window.Hide();
        }


You know have a floating window which is right-top aligned.......

Thanks to Mr. Jiang (pjiang@esri.com) for showing this in un-official silverlight viewer and Katy Dalton on sharing her Magnifying Glass code in the following forum (http://forums.arcgis.com/threads/50984-Magnify-and-Magnifying-Glass-Example?highlight=floatingwindow).

Note: You can look at Magnifying Glass to see how to load styles form XAML resources ......
0 Kudos