This is a migrated thread and some comments may be shown as answers.

Setting ToolTips using MVVM

2 Answers 165 Views
Map
This is a migrated thread and some comments may be shown as answers.
Nuno
Top achievements
Rank 1
Nuno asked on 02 Feb 2011, 06:24 AM
Hi,

I need to read Shapefiles manually to be able to remove some polygons. (Can't use MapShapeReader, right?)

MainPage.xaml:
<telerik:InformationLayer x:Name="StateLayer" ItemsSource="{Binding Source={StaticResource DataContext}, Path=States, Mode=TwoWay}">


MapViewModel.cs:
public List<FrameworkElement> States
{
get { return _states; }
set {    
if (this._states == value)
return;

_states = value;
OnPropertyChanged(
"States");
     }
}
...

this
.States = _allShapesToLoad; // I'm using MVVM to bind this.States to the InformationLayer ItemsSource


How can I set ToolTips to each polygon (State: StateName) from the ViewModel to the InformationLayer ?
Since I can't use MapShapeReader in this scenario I can't use ToolTipFormat="STATE_NAME"

Thank you,
Nuno

2 Answers, 1 is accepted

Sort by
0
Accepted
Andrey
Telerik team
answered on 04 Feb 2011, 10:31 AM
Hello Nuno,

You definetely can use MapShapeReader from the view model. So you can use ToolTipFormat property. For example:

public class MapViewModel : ViewModelBase
{
    private MapShapeReader shapeReader = new MapShapeReader();
    private List<FrameworkElement> _states = null;
  
    public MapViewModel()
    {
        shapeReader.Source = new Uri("/Telerik.RadMap.Silverlight.Q1;component/usa_states.shp", UriKind.RelativeOrAbsolute);
        shapeReader.ToolTipFormat = "STATE_NAME";
        shapeReader.PreviewReadCompleted += new PreviewReadShapesCompletedEventHandler(this.ShapePreviewReadCompleted);
        shapeReader.Read();
    }
  
    public List<FrameworkElement> States
    {
        get { return _states; }
        set
        {
            if (this._states == value)
                return;
  
            _states = value;
            OnPropertyChanged("States");
        }
    }
  
    private void ShapePreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
    {
        this.States = eventArgs.Items;
    }
}

public MainPage()
{
    InitializeComponent();
  
    this.informationLayer.DataContext = new MapViewModel();
}


Kind regards,
Andrey Murzov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Nuno
Top achievements
Rank 1
answered on 04 Feb 2011, 03:18 PM
Hi Andrey,

Once again, thank you very much for your wise help.

I was using the ReadCompleted event which was forcing me to create a dummy InformationLayer on the fly so that I could have access to its items collection after ReadComplet finishes. Now I switched to the PreviewReadCompleted event since I am able to reach the items collection through eventArgs.Items and as a bonus I don't need to create the dummy Information Layer!

To create ToolTips I was doing this way, for each State:

ToolTip tooltip = new ToolTip();
tooltip.Placement = System.Windows.Controls.Primitives.
PlacementMode.Mouse; 
tooltip.Content =
"State: " + stateName;
ToolTipService.SetToolTip(polygon, tooltip);


=> Now, it's just like this: shapeReader.ToolTipFormat = "STATE_NAME";

Cheers Andrey!

Nuno

 

 

Tags
Map
Asked by
Nuno
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Nuno
Top achievements
Rank 1
Share this question
or