views:

394

answers:

1

I am designing an application where I basically want to load geographical maps that are defined using paths (outlines of countries).

The Maps should be displayed on my Window and when I hover each country on the map, it should change color.

I managed to do this partially by exporting an svg map to xaml and including this xaml in a custom usercontrol. My current code is much like the one used to design THIS.

However, I now want to modify the software in such a way that I can:

a) load different maps at runtime; therefore there should be a way to load the paths into my control at runtime.

b) Get the map information in some form of xml file format that would not only allow me to store a map graphic, but also additional data blocks for other stuff/information.

I am really new to WPF and have absolutely no clue about how to go about this...

+1  A: 

As a starting point, you could look into dynamically loading a xaml file into a window. for instance, from your Window class code, you can do this (see XamlReader in System.Windows.Markup):

FileStream s = new FileStream("code.xaml", FileMode.Open);
DependencyObject root = (DependencyObject)XamlReader.Load(s);
this.Content = root;
Button button1 = (Button)LogicalTreeHelper.FindLogicalNode(root, "button1");
button1.Click += button1_Click;

to load xaml from a file called code.xaml and attach to the click event of a button called button1 contained within that xaml file:

<StackPanel 
  xmlns=
    "http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;
  <Button Name="button1" Margin="30">click me.</Button>
</StackPanel>

Note that the code within code.xaml doesn't full describe a window, but just what the content of the window is (ie the StackPanel is the top level element).

I'm sure this is still far from what you're looking for, but hopefully it'll be of some help!

Mark Synowiec