Geeks With Blogs

News Please visit me at my new blog!!

profile for Aligned at Stack Overflow, Q&A for professional and enthusiast programmers
"free in Christ Jesus from the law of sin and death." Romans 8:2 (ESV) Check out the Falling Plates video on YouTube.
more about the Gospel
And then listen to Francis Chan speaking at LifeLight in SD.

Programming and Learning from SD


This is my first blog on and I'm planning on occasionaly publishing things I've learned that I haven't found elsewhere in hopes of helping you out.

I've been annoyed with Silverlight and the Resource (.resx) files we use for translation. Every time I change text in the resource editor, I have to open the .designer.cs file and change the constructor to public. If it is not public, the resource string cannot be bound to in XAML, there is a runtime error. The code generation that happens on save, always changes it to internal. So I created a Macro that I tied to a hot key to make this quicker.

Here is the macro:

Public Module ResourceToPublic
Sub ResourceToPublic()
        DTE.ActiveDocument.Selection.LineDown(False, 31)
        DTE.ActiveDocument.Selection.CharRight(False, 8)
        DTE.ActiveDocument.Selection.Text = "public "
        ' DTE.ActiveDocument.Close()
    End Sub
End Module

This will move the cursor to the top left, then find the internal constructor (which is always in the same location, so I can use linedown and charright), change to public, move the cursor back to the top left and save the document.
To create the Macro in Visual Studio go to Tools -> Macros -> Macros Explorer. Right click on MyMacros and click new module. Paste the code into the correct spot. Then to make it even easier, bind the Macro to a hot key combination. I chose ctrl +, +. To do this, go to Tools -> Options -> Environment -> Keyboard. Type in ResourceToPublic in the textbox and select it. Then in push the keys you want (avoid overriding important ones) and click assign.
You're ready to save your self time and hopefully some grumbling!


Posted on Friday, November 4, 2011 12:55 PM Silverlight , Productivity | Back to top

Comments on this post: A quicker way to work with Resx files in Silverlight

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Aligned | Powered by: