wpf - Modifying a resource in C#? -


i have resource (mypoint) defined in xaml follows:

<path name="mypath">    <path.resources>       <point x:key="mypoint" x="200" y="200"/>    </path.resources> </path> 

in onapplytemplate override in corresponding c# code, use following reference resource.

mypointreference = (point)mypath.findresource("mypoint"); 

now, whenever modify value of mypointreference, let's say,

mypointreference.x = 30; 

it doesn't modify value of resource mypoint, changes value of mypointreference. how can make mypointreference actual reference xaml defined resource mypoint when modify value of mypointreference, modifying value of mypoint?

under covers when use resources extension in xaml dealing resourcedictionary , dealing adding struct (aka value type) passed value (aka copied) dictionary, , when request returned copy.

there no way pass value types reference when dealing resourcedictionary.

however, if need after modify copy can replace old copy in dictionary modified copy.

you can try calling:

mypath.setresourcereference("mypoint", mypointreference) 

you may want consider not doing in xaml or using resourcedictionary. can manage point in code behind , update , set path needed.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -