Controlling content of a DataTemplate

633
8
11-14-2011 04:14 AM
PaulHuppé
Occasional Contributor
Hi,

Is there a way to control the content of a DataTemplate depending on the value of a map layer label?  Below is part of my template.  What I want to do is to display an hyperlink for all map layers, but not for the Graphic Layer.  So, for all layers, I want to use the Hyperlink control and not show the CheckBox. And for the GraphicLayer, I want to show the CheckBox instead of the Hyperlink control.  Is there an easy way to do this?

Thanks,
Paul
    <esri:Legend.MapLayerTemplate>
     <DataTemplate>
      <StackPanel Orientation="Horizontal">
                            <CheckBox Content="{Binding Label}"
         IsChecked="{Binding IsEnabled, Mode=TwoWay}"
         IsEnabled="{Binding IsInScaleRange}" >
                            </CheckBox>
                            <HyperlinkButton Content="{Binding Label}" TargetName="_new" NavigateUri="http://www.nrcan.gc.ca/">
                                <ToolTipService.ToolTip>
                                    <StackPanel MaxWidth="400">
                                        <TextBlock FontWeight="Bold" Text="Show Metadata - Opens in new window" TextWrapping="Wrap" />
                                    </StackPanel>
                                </ToolTipService.ToolTip>
                            </HyperlinkButton>
0 Kudos
8 Replies
dotMorten_esri
Esri Notable Contributor
Create a custom value converter that flips visibility based on the type of the layer.
http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter(v=vs.95).aspx
0 Kudos
DominiqueBroux
Esri Frequent Contributor
There are more infos about what Morten suggests in this thread.
0 Kudos
PaulHuppé
Occasional Contributor
Thanks both of you. I will start on building a converter. Always something new to learn!
Paul
0 Kudos
PaulHuppé
Occasional Contributor
Question about the converter:

When I look at the samples, the converter is defined as:

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
   return value is GraphicsLayer ? Visibility.Visible : Visibility.Collapsed;
 }


Is it possible to have more than one parameter?  Can I do something like:

public object Convert(object value, Type targetType, object parameter1, object parameter2, System.Globalization.CultureInfo culture)
{
   // do something using the parameters which would set a visibility variable
   return visibility //return the value of my variable
 }


and in my XAML, I would have something like:

                            <CheckBox Content="{Binding Label}"
    IsChecked="{Binding IsEnabled, Mode=TwoWay}"
    IsEnabled="{Binding IsInScaleRange}"
                                Visibility="{Binding Layer, Converter={StaticResource VisConverter}, ConverterParameter=Layer, ConverterParameter='a string here'} " >
                            </CheckBox>
0 Kudos
PaulHuppé
Occasional Contributor
Found a way to do what I wanted with only one parameter.  But I am still interested to know if we can have more than one parameter.
0 Kudos
JenniferNery
Esri Regular Contributor
This seem related (Silverlight Forum: http://forums.silverlight.net/t/86106.aspx)
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Note that in your sample you don't need the layer as first parameter since it's already the main value to convert ('object value' parameter).

So you can use the ConverterParameter for your string.
0 Kudos
PaulHuppé
Occasional Contributor
Yes, that is true.  My question was more in the case where I would need to do something more complicated where I would require more information to do would be needed.
0 Kudos