1 <UserControl x:Class="LayerAction.MainPage" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:esri="http://schemas.esri.com/arcgis/client/2009" 7 xmlns:esriBehaviors="clr-namespace:ESRI.ArcGIS.Client.Behaviors;assembly=ESRI.ArcGIS.Client.Behaviors" 8 xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 9 mc:Ignorable="d" 10 d:DesignHeight="300" d:DesignWidth="400"> 11 12 <Grid x:Name="LayoutRoot" Background="White"> 13 14 <Grid.Resources> 15 <LinearGradientBrush x:Key="CommonGradient" StartPoint="0.5,0" EndPoint="0.5,1"> 16 <GradientStop Offset="0" Color="#99919191"/> 17 <GradientStop Offset="0.25" Color="#aa919191"/> 18 <GradientStop Offset="0.75" Color="#cc919191"/> 19 </LinearGradientBrush> 20 <Style x:Key="CommonBorder" TargetType="Border"> 21 <Setter Property="BorderBrush" Value="White" /> 22 <Setter Property="BorderThickness" Value="1" /> 23 <Setter Property="CornerRadius" Value="5" /> 24 <Setter Property="Background" Value="{StaticResource CommonGradient}" /> 25 <Setter Property="Opacity" Value="1" /> 26 </Style> 27 <Style x:Key="MenuItem" TargetType="Button"> 28 <Setter Property="Foreground" Value="White"/> 29 <Setter Property="HorizontalAlignment" Value="Left"/> 30 <Setter Property="VerticalAlignment" Value="Center"/> 31 <Setter Property="HorizontalContentAlignment" Value="Left"/> 32 <Setter Property="FontSize" Value="12" /> 33 <Setter Property="Template"> 34 <Setter.Value> 35 <ControlTemplate TargetType="Button"> 36 <Grid> 37 <VisualStateManager.VisualStateGroups> 38 <VisualStateGroup x:Name="CommonStates"> 39 <VisualState x:Name="Normal"> 40 <Storyboard> 41 <DoubleAnimation To="0" FillBehavior="HoldEnd" 42 Storyboard.TargetName="menuItemHighlight" 43 Storyboard.TargetProperty="Opacity" 44 Duration="0:0:0.3" /> 45 </Storyboard> 46 </VisualState> 47 <VisualState x:Name="MouseOver"> 48 <Storyboard> 49 <DoubleAnimation To="0.15" FillBehavior="HoldEnd" 50 Storyboard.TargetName="menuItemHighlight" 51 Storyboard.TargetProperty="Opacity" 52 Duration="0:0:0.3" /> 53 </Storyboard> 54 </VisualState> 55 </VisualStateGroup> 56 </VisualStateManager.VisualStateGroups> 57 <Rectangle x:Name="menuItemHighlight" Fill="#FFFFFFFF" 58 Opacity="0" Margin="0" /> 59 <ContentPresenter 60 Content="{TemplateBinding Content}" 61 ContentTemplate="{TemplateBinding ContentTemplate}" 62 VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 63 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 64 Margin="{TemplateBinding Padding}" /> 65 </Grid> 66 </ControlTemplate> 67 </Setter.Value> 68 </Setter> 69 </Style> 70 <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="10" Style="Circle" /> 71 </Grid.Resources> 72 73 <esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000"> 74 <esri:ArcGISTiledMapServiceLayer ID="MyBaseLayer" 75 Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" /> 76 <esri:ArcGISDynamicMapServiceLayer ID="MyDynamicLayer" 77 Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer" /> 78 <esri:FeatureLayer ID="MyFeatureLayer" IgnoreServiceScaleRange="True" 79 Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0"> 80 <esri:FeatureLayer.Clusterer> 81 <esri:FlareClusterer /> 82 </esri:FeatureLayer.Clusterer> 83 </esri:FeatureLayer> 84 </esri:Map> 85 86 <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Width="Auto" Height="Auto" Margin="10" > 87 <Border Style="{StaticResource CommonBorder}" Padding="10,3,10,3"> 88 <Border.Effect> 89 <DropShadowEffect /> 90 </Border.Effect> 91 <StackPanel> 92 <TextBlock Text="Layer Actions" Foreground="White" FontSize="14" FontWeight="Bold" Margin="4" /> 93 <Button Style="{StaticResource MenuItem}" 94 Content="Toggle Layer Visibility" > 95 <i:Interaction.Triggers> 96 <i:EventTrigger EventName="Click"> 97 <esri:ToggleLayerAction 98 LayerID="MyDynamicLayer" 99 TargetName="MyMap"/> 100 </i:EventTrigger> 101 </i:Interaction.Triggers> 102 </Button> 103 <Button Style="{StaticResource MenuItem}" 104 Content="Update Feature Layer"> 105 <i:Interaction.Triggers> 106 <i:EventTrigger PreviewInvoke="EventTrigger_PreviewInvoke" 107 EventName="Click"> 108 <esri:UpdateFeatureLayerAction 109 FeatureLayerID="MyFeatureLayer" 110 TargetName="MyMap" /> 111 </i:EventTrigger> 112 </i:Interaction.Triggers> 113 </Button> 114 <Button Style="{StaticResource MenuItem}" 115 Content="Zoom To Layer" > 116 <i:Interaction.Triggers> 117 <i:EventTrigger EventName="Click"> 118 <esri:ZoomToLayerAction 119 LayerID="MyFeatureLayer" 120 TargetName="MyMap" /> 121 </i:EventTrigger> 122 </i:Interaction.Triggers> 123 </Button> 124 </StackPanel> 125 </Border> 126 </Grid> 127 128 </Grid> 129 </UserControl>
1 using ESRI.ArcGIS.Client; 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Net; 6 using System.Windows; 7 using System.Windows.Controls; 8 using System.Windows.Documents; 9 using System.Windows.Input; 10 using System.Windows.Media; 11 using System.Windows.Media.Animation; 12 using System.Windows.Shapes; 13 14 namespace LayerAction 15 { 16 public partial class MainPage : UserControl 17 { 18 public MainPage() 19 { 20 InitializeComponent(); 21 } 22 private void EventTrigger_PreviewInvoke(object sender, System.Windows.Interactivity.PreviewInvokeEventArgs e) 23 { 24 FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] as FeatureLayer; 25 featureLayer.Where = featureLayer.Where == null ? "POP2000 > 1000" : null; 26 } 27 28 } 29 }