Select to view content in your preferred language

Find and Formatting

2220
25
01-06-2011 11:18 AM
JayKappy
Frequent Contributor
I am trying to format a window after I run the FIND example from the API examples

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Find

I have this working but I do not want a grid/scrollviewer to display my results...I want to display them in a more meaningful fashion...

ex
PID: field value
Address: field value

PID: field value
Address: field value

PID: field value
Address: field value

How can I do this...I am doign this but only for the Identify and that is only one record showing...
I cant figure out how to do this in respect to the FIND example and outside a grid...

Any thoughts....

Thanks
0 Kudos
25 Replies
JayKappy
Frequent Contributor
Just a couple questions about the selecting....Because I think I am starting down teh same path where I am trying to do soemthing a million different ways...

This example given to me seems to have the action event on the Graphic Click....where it will perform some act when the user selects the Graphic????
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#CustomSymbols

                    <esri:GraphicsLayer ID="MyGraphicsLayerListBox" MouseLeftButtonDown="GraphicsLayer_MouseLeftButtonDown">                        <esri:GraphicsLayer.Graphics>
                            <esri:Graphic Symbol="{StaticResource StrobeMarkerSymbol}">
                                <esri:MapPoint X="-50" Y="-10" />
                            </esri:Graphic>
                        </esri:GraphicsLayer.Graphics>
                    </esri:GraphicsLayer>


        Private Sub GraphicsLayer_MouseLeftButtonDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Client.GraphicMouseButtonEventArgs)
            If (e.Graphic.Selected) Then
                e.Graphic.UnSelect()
            Else
                e.Graphic.Select()
            End If
        End Sub


Where as I am trying to call the StrobeMarkerrSymbol reference from the SelectionChanged Event
<ListBox x:Name="imageList" Height="200" ScrollViewer.VerticalScrollBarVisibility="Visible                  
BorderThickness="0"
Foreground="White" Background="Transparent"
SelectionChanged="imageList2_SelectionChanged">
SNIP....



I cant see from the ealier example of the Flicker images that this was being done OnEnter of a TextBlock....Exaclty what I am trying to do...
I am confused with the mention of FrameworkElement adn DataContext....do I need to point this to my Listbox?

I guess I am confused...If I call the event to SELECT or UNSELECT from the SelectionChange event of the listbox how to I bind it to the specific Graphics Layer, AND how specifiy the StrobeMarkerSymbol Animation?

Private Sub TextBlock_MouseEnter(sender As Object, e As MouseEventArgs)
 Dim p As Photo = TryCast(TryCast(sender, FrameworkElement).DataContext, Photo) 
             Dim g As Graphic = getGraphic(p)
 If g IsNot Nothing Then
  g.[Select]()
  'Activate the selection state
   'Pop the graphic on top of other graphics
  g.SetZIndex(1)
 End If
End Sub

Private Sub TextBlock_MouseLeave(sender As Object, e As MouseEventArgs)
 Dim p As Photo = TryCast(TryCast(sender, FrameworkElement).DataContext, Photo)
 Dim g As Graphic = getGraphic(p)
 If g IsNot Nothing Then
  g.UnSelect()
  'Deactivate selection state
   'reset the graphic Z index
  g.SetZIndex(0)
 End If
End Sub
0 Kudos
JayKappy
Frequent Contributor
HERE IS THE SelectionChanged example

What is "Photo" refering to? What parameter is that? This is also from the SpatialFlicker example posted previously...
But again I dont see how the Code that changes the graphic is being called....The "StrobeMarkerSymbol"

Private Sub imageList_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
 myMap.PanTo(TryCast(imageList.SelectedItem, Photo).Location)
End Sub



Guess I am confuse with the Photo reference...I like the pan to option as well as the Select and Unselect.
I have the Story boards set up...right now I have the MouseOver working in the map...by setting the graphic to the correct story board.
               resultFeature.Symbol = TryCast(LayoutRoot.Resources("StrobeMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
                graphicsLayer.Graphics.Add(resultFeature)


In that same story board I have a SelectedStates set up...

SNIP
<VisualStateGroup x:Name="SelectionStates">
     <VisualState x:Name="Selected">
            <Storyboard RepeatBehavior="ForEver">
                        <DoubleAnimation BeginTime="0"                                                                                                Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
        From="1" To="10" Duration="00:00:01"/>
                        <DoubleAnimation BeginTime="0"
      Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
      From="1" To="10" Duration="00:00:01" />
                        <DoubleAnimation BeginTime="0"
                              Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)"
                               From="1" To="0" Duration="00:00:01" />
              </Storyboard>
SNIP



Just need to set the Pan to properly and the selected/unselected

Something like this???

Private Sub imageList_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
 myMap.PanTo(TryCast(imageList.SelectedItem, Photo).Location)

        If (e.Graphic.Selected) Then
            e.Graphic.UnSelect()
        Else
            e.Graphic.Select()
        End If
End Sub


THANKS AGAIN.......
0 Kudos
JenniferNery
Esri Regular Contributor
In that SDK Sample, create a symbol template similar to "SelectRectangleMarkerSymbol". Notice how it defines SelectionStates, a ColorAnimation is done on Selected state.

If you go to the Live view, you can see that the outline of the rectangle changes from blue to blinking red when selected and back to blue when not selected. You need to create something similar to distinguish the selected graphic.

In the SDK Sample, GraphicsLayer_MouseLeftButtonDown is there to allow you to select the graphic on mouse left button down. You cannot use the same event handler for the ListBox MouseLeftButtonDown event because they will have different EventArgs.

Since you want to select the graphic based on the selection on the ListBox, you can use the ListBox SelectionChanged event. I don't know which solution you end up using so I cannot tell what type your ListBox contains. If it is a Graphic then you can type cast as such and call Select()/UnSelect().
Private Sub imageList_SelectionChanged(sender As Object, e As SelectionChangedEventArgs)
 For Each item As var In e.RemovedItems
  Dim g As Graphic = TryCast(item, Graphic)
  g.UnSelect()
 Next
 For Each item As var In e.AddedItems
  Dim g As Graphic = TryCast(item, Graphic)
  g.[Select]()
 Next
End Sub
0 Kudos
JayKappy
Frequent Contributor
Thanks again....yea thats the part thats confusing me....the var in your example...is there somewhere that exaplains this statement more...the parameters item, graphic etc...

        For Each item As var In e.AddedItems
            Dim g As Graphic = TryCast(item, Graphic)
            g.[Select]()
        Next


For each Items As ? , in the listbox (items that were added, or are there)
Dim the graphic as the selected item in the listbox?
then select it, thus resulting in the markersymbol beign called which changes the symbolozation.
That about it or close?

As for my project I did this....

xaml
            <Grid x:Name="resultsPanel"  Width="200" 
  HorizontalAlignment="Left" VerticalAlignment="Top"
  Margin="10,40,0,10">
                <Border Padding="2" Style="{StaticResource darkBorder}">
                    <StackPanel Orientation="Vertical" >
                        <ListBox x:Name="imageList" Height="200"  ScrollViewer.VerticalScrollBarVisibility="Visible" 
    BorderThickness="0"
    Foreground="White" Background="Transparent"
    SelectionChanged="imageList2_SelectionChanged">
                            <ListBox.ItemTemplate>
                                <DataTemplate>                                
                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
                                        <StackPanel Margin="1">
                                            <TextBlock Foreground="White" Text="{Binding Attributes[TYPE]}" />
                                        </StackPanel>
                                        <StackPanel Margin="5,0,0,0" Orientation="Vertical">
                                            <TextBlock Foreground="White" Text="{Binding Attributes[CITY_NAME], StringFormat='City Name: \{0\}'}" >
                                                  <TextBlock.Effect>
                                                      <DropShadowEffect/>
                                                  </TextBlock.Effect>
                                            </TextBlock>
                                        </StackPanel>                                                                                                               
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </StackPanel>
                </Border>
            </Grid>


VB - I used a query

    Private Sub ExecuteList_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        '' Query task initialization
        Dim queryTask As New QueryTask("http://gis.org/arcgis/rest/services/MG_Test_WGS84/MapServer/1")
        AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompletedListBox
        AddHandler queryTask.Failed, AddressOf QueryTask_FailedSearch

        Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
        query.OutFields.Add("*")
        query.ReturnGeometry = True
        query.Where = "1=1"
        query.OutSpatialReference = MyMap.SpatialReference
        queryTask.ExecuteAsync(query)
End Sub


    Private Sub QueryTask_ExecuteCompletedListBox(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)

        ' Set the Target Graphics Layer
        Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayerListBox"), GraphicsLayer)
        ' Clear previous results
        graphicsLayer.ClearGraphics()

        ' Check for new results 
        Dim featureSet As FeatureSet = args.FeatureSet

        ' Set the Source of the ListBox to the features returned by the query
        imageList.ItemsSource = args.FeatureSet.Features

        If featureSet.Features.Count > 0 Then
            For Each resultFeature As Graphic In featureSet.Features
                resultFeature.Symbol = TryCast(LayoutRoot.Resources("StrobeMarkerSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
                graphicsLayer.Graphics.Add(resultFeature)
            Next
        Else
            MessageBox.Show("No features found")
        End If
    End Sub



THIS IS MY MARKER SYMBOL FOR select and unselect, as well as my MouseOver (WHICH IS WORKING)

            <esri:MarkerSymbol x:Key="StrobeMarkerSymbol">
                <esri:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Canvas>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="MouseOver">
                                            <Storyboard RepeatBehavior="ForEver">

                                            <DoubleAnimation BeginTime="0"
          Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
          From="1" To="10" Duration="00:00:01" />
                                             <DoubleAnimation BeginTime="0"
          Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
          From="1" To="10" Duration="00:00:01" />
                                            <DoubleAnimation BeginTime="0"
         Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)"
          From="1" To="0" Duration="00:00:01" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Normal" />
                                </VisualStateGroup>
                                
                                <VisualStateGroup x:Name="SelectionStates">
                                    <VisualState x:Name="Selected">
                                        <Storyboard RepeatBehavior="ForEver">

                                            <DoubleAnimation BeginTime="0"
Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)"
   From="1" To="10" Duration="00:00:01" />
                                     <DoubleAnimation BeginTime="0"
              Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)"
   From="1" To="10" Duration="00:00:01" />
                          <DoubleAnimation BeginTime="0"
  Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)"
   From="1" To="0" Duration="00:00:01" />
                          </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Unselected" />
                                    
                    </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>

                            <Ellipse Height="10" Width="10" Canvas.Left="-5" Canvas.Top="-5" 
                 RenderTransformOrigin="0.5,0.5" x:Name="ellipse
                            IsHitTestVisible="False">
                                <Ellipse.RenderTransform>
                                    <ScaleTransform />
                                </Ellipse.RenderTransform>
                                <Ellipse.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Color="#00FF0000" />
                                        <GradientStop Color="#FFFF0000" Offset="0.25"/>
                                        <GradientStop Color="#00FF0000" Offset="0.5"/>
                                        <GradientStop Color="#FFFF0000" Offset="0.75"/>
                                        <GradientStop Color="#00FF0000" Offset="1"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>

                            <Ellipse Height="10" Width="10" Canvas.Left="-5" Canvas.Top="-5" 
        Fill="#FFFF0000" x:Name="ellipse1"/>
                        </Canvas>
                    </ControlTemplate>
                </esri:MarkerSymbol.ControlTemplate>
            </esri:MarkerSymbol>
0 Kudos
JayKappy
Frequent Contributor
THINK I GOT IT

I have the SelectionChanged Working

        For Each item As Graphic In e.RemovedItems
            Dim g As Graphic = TryCast(item, Graphic)
            g.UnSelect()
        Next
        For Each item As Graphic In e.AddedItems
            Dim g As Graphic = TryCast(item, Graphic)
            g.[Select]()
        Next



I have the MouseLeftButtonDown on the actual Graphic working

        If (e.Graphic.Selected) Then
            e.Graphic.UnSelect()
        Else
            e.Graphic.Select()
        End If


Just trying to get the MouseEnter and MouseLeave in the Listbox working....Little Puzzled at this one...
Confused because there is no selection being done in the listbox...its just a hover event...I thought the second example above would work....
I cant thank you enough fofr your help and guidance....very appreciated....

    Private Sub imageList2_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)

        For Each Item As Graphic In ???????
            Dim g As Graphic = TryCast(Item, Graphic)
            g.[Select]()
        Next

    End Sub
0 Kudos
JayKappy
Frequent Contributor
GOT IT WOO HOOOOOO!!!!!

THANKS FOR ALL YOUR HELP....VERY VERY VERY APPRECIATED.....

    Private Sub imageList2_MouseEnter(ByVal sender As Object, ByVal e As MouseEventArgs)
        Dim Item As Graphic = TryCast(TryCast(sender, FrameworkElement).DataContext, Graphic)
        Dim g As Graphic = TryCast(Item, Graphic)
        g.[Select]()
    End Sub
0 Kudos