Putting legend control in child window

549
2
12-13-2012 12:52 AM
SaurabhDasgupta
New Contributor II
Hi,
My application having a legend control which displays the layer information for the map. I have a child window where I want to put the legend information. I am able to extract the legend information from the main xaml page to the child window but I am unable to put it to the child window.

My mainpage xaml code is

<Button x:Name="btnPrint" Height="30" Width="30" Click="btnPrint_Click" Canvas.Left="573" Canvas.Top="14">
<Image Source="Images/Printer.png" Canvas.Left="555" Canvas.Top="6" />
</Button>

Mainpagexaml.cs code is

MapPrintView printView = new MapPrintView();
printView.DataContext = viewModel;
printView.BuildMap();

//If there are layers to build a legend for, build the legend.
if (viewModel.MapGraphics != null && viewModel.MapGraphics.Count > 0)
{
printView.CreateLegend();
}

My child widow code where I want to put my legend information

MapPrintView.xaml
<esriToolkit:Legend Map="{Binding ElementName=edmsMap}" x:Name="printMapLegend" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,53,6,6" Grid.Row="3" Grid.Column="2">
<esriToolkit:Legend.MapLayerTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox x:Name="ColorTextBox" Width="50" Height="50"
Background="{Binding Label}"/>

<CheckBox x:Name="legendSelectionCheckBox" Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}"
>
</CheckBox>
<Button x:Name="deleteLayerButton" Width="25" Height="25" Tag="{Binding Label}" >
<Image Source="Images/delete.png" ToolTipService.ToolTip="Remove Program Type"/>
</Button>
<Button x:Name="showResultButton" Width="25" Height="25" Tag="{Binding Label}" >
<Image Source="Images/reports-icon.png" ToolTipService.ToolTip="Show Program Type Results"/>
</Button>
<Button x:Name="selectGraphicResults" Width="25" Height="25" Tag="{Binding Label}" >
<Image Source="Images/query_rectangle.png" ToolTipService.ToolTip="Select an area on the Map to display its results"/>
</Button>

</StackPanel>
</DataTemplate>
</esriToolkit:Legend.MapLayerTemplate>
<esriToolkit:Legend.LayerTemplate>
<DataTemplate>
<CheckBox x:Name="legendSelectionCheckBox" Content="{Binding Label}"
IsChecked="{Binding IsEnabled, Mode=TwoWay}"
IsEnabled="{Binding IsInScaleRange}"
>
</CheckBox>

</DataTemplate>
</esriToolkit:Legend.LayerTemplate>
</esriToolkit:Legend>


MapPrintView.xaml.cs

public void CreateLegend()
{
printMapLegend = viewModel.CreateLegendInformation();
}

public Legend CreateLegendInformation()
{
return mapLegend;
}

I am getting the legend information in this last line code of "mapLegend" but unable to put it to the child window. Can anybody please help me on this.

Thanks in advance.

~Saurabh.
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
If your legend control is already in your main view, you can't put it in a child window.
Silverlight doesn't support adding the same UIElement in 2 places.
Instead, either create a new legend by code (though you can defined the legend style only once in the ressources) or remove the legend from your main view before adding it to your child window.
0 Kudos
SaurabhDasgupta
New Contributor II
Thanks for your reply Dominique, will try it in ways of adding the legend using code.

~Saurabh.
0 Kudos