Specifying resource keys using data binding
Posted: 12 Sep 2022, 19:47
Hello!
I've been struggling with the proper way to setup a map system we've created in Noesis.
The basics are this: we have a bunch of different icons we want to display on the map: stores, monsters, other points of interest. This pretty much comes down to a list "icons" that have this type of data:
- what type of icon is it
- where is it (position, rotation)
We want to create vector icons for the map. So, up until now, we've split the icons into different lists based on the "type" if the icon. Then, we have a data template for each "type" of icon hat has it's own <Path> element that shows the icon.
The thing that is getting annoying is that now we have so many different lists of "types" of icons, and it seems somewhat silly as these are all 90% the same with just the <Path> data differing.
So, I started looking at an experiment of moving the "paths" into a separate name shared resource. That seemed to work ok:
and then i could refer to the path from a data template:
So that all seemed to work -- but now what I really want to do is instead of explicitly specifying "StoreIcon", I want that data to be bound dynamically. Ie, on my "Icon" data model, add a new "IconName" property which would be set to 'StoreIcon' or 'MonsterIcon'. ie something like this:
However, it doesn't seem like this works..
I ran into this blob post, which seems to be doing even more than what I need, but might solve it:
http://blog.functionalfun.net/2009/12/s ... ta_31.html
The method has to do with creating a converter that converts the string into the proper static resource.
Is that the best way to do this? Or is there another/better method?
thanks,
sam
I've been struggling with the proper way to setup a map system we've created in Noesis.
The basics are this: we have a bunch of different icons we want to display on the map: stores, monsters, other points of interest. This pretty much comes down to a list "icons" that have this type of data:
- what type of icon is it
- where is it (position, rotation)
We want to create vector icons for the map. So, up until now, we've split the icons into different lists based on the "type" if the icon. Then, we have a data template for each "type" of icon hat has it's own <Path> element that shows the icon.
The thing that is getting annoying is that now we have so many different lists of "types" of icons, and it seems somewhat silly as these are all 90% the same with just the <Path> data differing.
So, I started looking at an experiment of moving the "paths" into a separate name shared resource. That seemed to work ok:
Code: Select all
<Path x:Key="StoreIcon" Data="..." />
<Path x:Key="MonsterIcon" Data="..." />
Code: Select all
<Path Data="{Binding Source={StaticResource StoreIcon}, Path=Data}" />
Code: Select all
<Path Data="{Binding Source={StaticResource {Binding IconName}, Path=Data}" />
I ran into this blob post, which seems to be doing even more than what I need, but might solve it:
http://blog.functionalfun.net/2009/12/s ... ta_31.html
The method has to do with creating a converter that converts the string into the proper static resource.
Is that the best way to do this? Or is there another/better method?
thanks,
sam