I'm having difficulty displaying design-time data in a user control that makes heavy use of RadMap.
The method I use for design-time is similar to the Sophia Car Rental project. I set the data context in the UserControl tag as follows:
xmlns:design="clr-namespace:XYZ.ViewModel.Design"
d:DataContext="{d:DesignInstance d:Type=design:PlanViewModel, d:IsDesignTimeCreatable=True}"
I then create a class that inherits from my run-time view model, but is used to put some dummy data on the screen. Here I am adding an information layer and setting the background to blue so I can see it. Also note the compiler directives to keep this design-time stuff out of my release a..
#if DESIGNONLY
using System.Windows.Media;
using Telerik.Windows.Controls.Map;
namespace XYZ.ViewModel.Design
{
public class PlanViewModel : PlanView.PlanViewModel
{
public override void SetControlState(bool resetToInitialState = false)
{
base.SetControlState(resetToInitialState);
var layer = new InformationLayer
{
Background = Brushes.Blue
};
Layers.Add(layer);
}
}
}
#endif
Lastly, this happens in the SetControlState() method, which in this case is called in the base class when the map's InitializationCompleted method is called.
The Layers Collection is defined as such;
public ObservableCollection<InformationLayer> Layers { get; private set; }
and the user control definition looks like this;
<telerik:RadMap HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}" Center="{Binding Center, Mode=TwoWay}"
UseDefaultLayout="False" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4"
x:Name="MapContainer" ItemsSource="{Binding Layers}">
<!-- Send the mouse position to the view model so we can fake the mouse position control with our own data -->
<telerik:EventToCommandBehavior.EventBindings>
<telerik:EventBinding Command="{Binding MousePositionCommand}" EventName="MouseMove"
PassEventArgsToCommand="True" RaiseOnHandledEvents="True"/>
</telerik:EventToCommandBehavior.EventBindings>
<!-- This provider gives us a blank slate that can handle UTM based data -->
<telerik:RadMap.Providers>
<telerik:EmptyProvider>
<telerik:EmptyProvider.Projection>
<telerik:EPSG900913Projection />
</telerik:EmptyProvider.Projection>
</telerik:EmptyProvider>
</telerik:RadMap.Providers>
</telerik:RadMap>
If I create the InformationLayer in XAML, I see a blue map as expected. If I do it in code - nothing. This technique works perfectly with other controls, so I'm somewhat at a loss as to what is happening, especially since similar code at run time creates a map with an InformationLayer with a blue background.
Any suggestions are welcome.
The method I use for design-time is similar to the Sophia Car Rental project. I set the data context in the UserControl tag as follows:
xmlns:design="clr-namespace:XYZ.ViewModel.Design"
d:DataContext="{d:DesignInstance d:Type=design:PlanViewModel, d:IsDesignTimeCreatable=True}"
I then create a class that inherits from my run-time view model, but is used to put some dummy data on the screen. Here I am adding an information layer and setting the background to blue so I can see it. Also note the compiler directives to keep this design-time stuff out of my release a..
#if DESIGNONLY
using System.Windows.Media;
using Telerik.Windows.Controls.Map;
namespace XYZ.ViewModel.Design
{
public class PlanViewModel : PlanView.PlanViewModel
{
public override void SetControlState(bool resetToInitialState = false)
{
base.SetControlState(resetToInitialState);
var layer = new InformationLayer
{
Background = Brushes.Blue
};
Layers.Add(layer);
}
}
}
#endif
Lastly, this happens in the SetControlState() method, which in this case is called in the base class when the map's InitializationCompleted method is called.
The Layers Collection is defined as such;
public ObservableCollection<InformationLayer> Layers { get; private set; }
and the user control definition looks like this;
<telerik:RadMap HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}" Center="{Binding Center, Mode=TwoWay}"
UseDefaultLayout="False" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="4"
x:Name="MapContainer" ItemsSource="{Binding Layers}">
<!-- Send the mouse position to the view model so we can fake the mouse position control with our own data -->
<telerik:EventToCommandBehavior.EventBindings>
<telerik:EventBinding Command="{Binding MousePositionCommand}" EventName="MouseMove"
PassEventArgsToCommand="True" RaiseOnHandledEvents="True"/>
</telerik:EventToCommandBehavior.EventBindings>
<!-- This provider gives us a blank slate that can handle UTM based data -->
<telerik:RadMap.Providers>
<telerik:EmptyProvider>
<telerik:EmptyProvider.Projection>
<telerik:EPSG900913Projection />
</telerik:EmptyProvider.Projection>
</telerik:EmptyProvider>
</telerik:RadMap.Providers>
</telerik:RadMap>
If I create the InformationLayer in XAML, I see a blue map as expected. If I do it in code - nothing. This technique works perfectly with other controls, so I'm somewhat at a loss as to what is happening, especially since similar code at run time creates a map with an InformationLayer with a blue background.
Any suggestions are welcome.