Widgets 整理

1.滑动条

http://www.newnaw.com/pub/sl/031.html

<--!grid中的内容-->

<Grid x:Name="slidergrid" HorizontalAlignment="Left" VerticalAlignment="Center" Background="Azure" Margin="20">
        <StackPanel Orientation="Vertical">
            <Button x:Name="btnzoomin" Content="+" Click="btnzoomin_Click" />
            <Slider x:Name="sliderLOD" Orientation="Vertical"  Height="200" SmallChange="1" LargeChange="1"  Minimum="0" Cursor="Hand" ValueChanged="slider1_ValueChanged" />
            <Button x:Name="btnzoomout" Content="-" Click="btnzoomout_Click" />
        </StackPanel>
    </Grid>

 

cs文件后台代码

代码
   
     
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.ComponentModel;

namespace customcontrol
{
public partial class mapslider : UserControl
{
private mymap map = new mymap();
public ESRI.ArcGIS.Map Map
{
get
{
return map.Map;
}
set
{
map.Map
= value;
if (map.Map != null )
{
Map.ExtentChanged
+= new EventHandler < ESRI.ArcGIS.ExtentEventArgs > (map_ExtentChanged);
Map.SnapToLevels
= true ;
((ESRI.ArcGIS.ArcGISTiledMapServiceLayer)Map.Layers[
0 ]).Initialized += new EventHandler < EventArgs > (layer0_initialized);
}

}
}

private void layer0_initialized( object o,EventArgs e)
{
sliderLOD.Maximum
= ((ESRI.ArcGIS.ArcGISTiledMapServiceLayer)Map.Layers[ 0 ]).TileInfo.Lods.Length - 1 ;
}

public mapslider()
{
InitializeComponent();
}

private void slider1_ValueChanged( object sender, RoutedPropertyChangedEventArgs < double > e)
{
if (map.Map != null )
{
Map.ZoomToResolution(((ESRI.ArcGIS.ArcGISTiledMapServiceLayer)Map.Layers[
0 ]).TileInfo.Lods[Convert.ToInt32(e.NewValue)].Resolution);
}
}

private void map_ExtentChanged( object o, ESRI.ArcGIS.ExtentEventArgs e)
{
ESRI.ArcGIS.ArcGISTiledMapServiceLayer layer
= Map.Layers[ 0 ] as ESRI.ArcGIS.ArcGISTiledMapServiceLayer;
int i;
for (i = 0 ; i < layer.TileInfo.Lods.Length; i ++ )
{
if (Map.Resolution == layer.TileInfo.Lods[i].Resolution)
break ;
}

sliderLOD.Value
= i;
}

private void btnzoomin_Click( object sender, RoutedEventArgs e)
{
sliderLOD.Value
+= 1 ;
}

private void btnzoomout_Click( object sender, RoutedEventArgs e)
{
sliderLOD.Value
-= 1 ;
}
}

// 执行了这个接口后,当在主页面page.xaml.cs中给Map赋值的时候,就能返到set语句中,以便执行绑定事件的代码
public class mymap:INotifyPropertyChanged
{
private ESRI.ArcGIS.Map map;
public ESRI.ArcGIS.Map Map
{
get { return map;}
set
{
map
= value;
if (PropertyChanged != null )
{
PropertyChanged(
this , new PropertyChangedEventArgs( " Map " ));
}
}
}

public event PropertyChangedEventHandler PropertyChanged;

}
}

 

你可能感兴趣的:(widget)