Select to view content in your preferred language

Attachment editor bind 2 layers??

1069
4
10-26-2011 02:33 PM
DavidAshton
Frequent Contributor
I want to use the attachment editor with two feature layers. I have it up and running for on but I'm unsure how to bind two layers
 <esri:AttachmentEditor x:Name="MyAttachmentEditor" VerticalAlignment="Top" Margin="20,5,20,20" 
                             Background="WhiteSmoke" Width="280" Height="190" HorizontalAlignment="Right"     

                 
                             FeatureLayer="{Binding Layers[TPOINTS;TLINES], ElementName=Map}" 
                             
                             Filter="All Files (*.*)|*.*|Image Files|*.tif;*.jpg;*.gif;*.png;*.bmp|Text Files (.txt)|*.txt" 
                             FilterIndex="1" Multiselect="True"
                             UploadFailed="MyAttachmentEditor_UploadFailed">
                            </esri:AttachmentEditor>
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
You cannot bind the AttachmentEditor to two layers, you can however, set this in code-behind to be able to work with two layers. Or another way is to use ComboBox.SelectedItem, if ComboBox.ItemsSource include the two feature layers.

<esri:AttachmentEditor FeatureLayer="{Binding ElementName=MyComboBox, Path=SelectedItem}"/>
0 Kudos
DavidAshton
Frequent Contributor
Jennifer,

Thanks for the reply,

So I went ahead and added two attachment editors and the right attachment editor is activated when the correct feature layer is selected (using the selection or add button from the editor tool bar).

Here's my xaml


 <!-- Attachment Tools -->
        <!-- FeatureLayer="{Binding Layers[DISTRICTPOINTS], ElementName=Map}"-->

        <Grid x:Name="AttachmentGrid"  HorizontalAlignment="Right"  VerticalAlignment="Center" Margin="0,160,15,0" Visibility="Collapsed">
            <Border Background="{StaticResource CommonPanelBorderBackgroundBrush}" BorderBrush="{StaticResource CommonBorderBrush}" BorderThickness="1" CornerRadius="6" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                <Border Effect="{StaticResource miniDropShadow}" Style="{StaticResource RibbonElementBorder}" Padding="15" Margin="10" >


                    <StackPanel Orientation="Vertical">
                            <TextBlock Text="Click on a point feature to select it, and click the 'Add' button to attach a file." 
                       Width="275" TextAlignment="Left" Margin="20,20,20,5" TextWrapping="Wrap" FontWeight="Bold"/>
                            
                        <esri:AttachmentEditor x:Name="MyAttachmentEditor" VerticalAlignment="Top" Margin="20,5,20,20" 
                             Background="WhiteSmoke" Width="280" Height="190" HorizontalAlignment="Right"                              
                             FeatureLayer="{Binding Layers[TPOINTS], ElementName=Map}"
                             Filter="All Files (*.*)|*.*|Image Files|*.tif;*.jpg;*.gif;*.png;*.bmp|Text Files (.txt)|*.txt" 
                             FilterIndex="1" Multiselect="True"
                             UploadFailed="MyAttachmentEditor_UploadFailed">
                            </esri:AttachmentEditor>

                        <esri:AttachmentEditor x:Name="MyAttachmentEditor1" VerticalAlignment="Top" Margin="20,5,20,20" 
                             Background="WhiteSmoke" Width="280" Height="190" HorizontalAlignment="Right"                              
                             FeatureLayer="{Binding Layers[TLINES], ElementName=Map}"
                             Filter="All Files (*.*)|*.*|Image Files|*.tif;*.jpg;*.gif;*.png;*.bmp|Text Files (.txt)|*.txt" 
                             FilterIndex="1" Multiselect="True"
                             UploadFailed="MyAttachmentEditor_UploadFailed">
                        </esri:AttachmentEditor>

                    </StackPanel>

                    </Border>
                </Border>

            <Image Source="images/CloseX.png" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="3" Stretch="None" Cursor="Hand" ToolTipService.ToolTip="Close" MouseLeftButtonUp="ViewAttribute_Click" >

            </Image>
            
        </Grid>


        <!-- END Attachment Tools-->
        


Here's my code behind

private void EditorWidget_EditCompleted(object sender, Editor.EditEventArgs e)
        {

            if (e.Action == Editor.EditAction.ClearSelection) //|| e.Action == Editor.EditAction.Select
            {
                MyAttachmentEditor.GraphicSource = null;
                MyAttachmentEditor1.GraphicSource = null;
            }
            else if (e.Action == Editor.EditAction.Add || e.Action == Editor.EditAction.Select)
            {
                foreach (var edit in e.Edits)
                {
                    if (e.Action == Editor.EditAction.Add || edit.Graphic.Selected)
                    {

                        MyAttachmentEditor1.GraphicSource = edit.Graphic;
                        MyAttachmentEditor.GraphicSource = edit.Graphic;

                    

                        break;
                    }
                }
            }



This is all working and as I previously stated when the correct feature layer is selected (using the selection or add button from the editor tool bar) the correct attachment editor is activated and I can attach a picture.  So I was wondering instead of adding a drop down list and since this is already being controlled by the select and add button on the editor tool bar; could I just throw a if statement in there to control which attribute editor to display?  Something like this but I am not sure what to write:



                    if (e.Action == Editor.EditAction.Add || edit.Graphic.Selected)
                    {


                //        MyAttachmentEditor1.GraphicSource = edit.Graphic;
               //         MyAttachmentEditor.GraphicSource = edit.Graphic;

                    if (var edit in e.Edits == polyline)
                       {
                          MyAttachmentEditor1 = Visibility.Visible;
                       MyAttachmentEditor1.GraphicSource = edit.Graphic;
                       {

                       if (var edit in e.Edits == point)
                       {
                       MyAttachmentEditor = Visibility.Visible;
                       MyAttachmentEditor.GraphicSource = edit.Graphic;
                       {


                        break;
                    }




What I'm having trouble with is the if clause...can you help??

Thanks
Dave
0 Kudos
JenniferNery
Esri Regular Contributor
Okay, I think I understand the problem now. Since EditorWidget works with multiple feature layers, you want AttachmentEditor to be flexible enough to work with any of these feature layers.

In that case, do not set AttachmentEditor.FeatureLayer property in XAML (remove the binding), set this in EditorWidget_EditCompleted event handler instead, same place where you set its GraphicSource.

void EditorWidget_EditCompleted(object sender, Editor.EditEventArgs e)
{
 if (e.Action == Editor.EditAction.Add || e.Action == Editor.EditAction.Select)
 {
  foreach (var edit in e.Edits)
  {
   if (edit.Layer is FeatureLayer)
   {
    if (e.Action == Editor.EditAction.Add || edit.Graphic.Selected)
    {
     MyAttachmentEditor.FeatureLayer = edit.Layer as FeatureLayer;
     MyAttachmentEditor.GraphicSource = edit.Graphic;
    }
   }
  }
 }
}
0 Kudos
DavidAshton
Frequent Contributor
Thnaks Jennifer...That works!

David
0 Kudos