When I modify my resource file (.resx
) add text or modify, the constructor of my resource always go to internal and after that, when I run my silverlight I have an error in my binding XAML.
Is there a way to avoid this scenario? I need to go in the designer of my resource and put the constructor to public to solve the problem
I use my resource like this in my xaml file
<UserControl.Resources>
<resources:LibraryItemDetailsView x:Key="LibraryItemDetailsViewResources"></resources:LibraryItemDetailsView>
</UserControl.Resources>
<TextBlock FontSize="12" FontWeight="Bold" Text="{Binding Path=FileSelectedText3, Source={StaticResource LibraryItemDetailsViewResources}}"></TextBlock>
Another way to do this without code changes is as below. Worked well for me.
http://guysmithferrier.com/post/2010/09/PublicResourceCodeGenerator-now-works-with-Visual-Studio-2010.aspx
You can create a public class that exposes the resources through a property:
public class StringsWrapper
{
private static LibraryItemDetailsView _view = null;
public LibraryItemDetailsView View
{
get
{
if (_view == null)
{
_view = new LibraryItemDetailsView();
}
return _view;
}
}
}
Then in your XAML you can access your resource:
<UserControl.Resources>
<StringsWrapper x:Key="LibraryItemDetailsViewResources"></StringsWrapper>
</UserControl.Resources>
<TextBlock FontSize="12" FontWeight="Bold" Text="{Binding Path=View.FileSelectedText3, Source={StaticResource LibraryItemDetailsViewResources}}"></TextBlock>
This way the resx constructor can be internal!
Well, what I did was to add a command line utility to pre-build event of each Silverlight project that replaces each internal
string
with public
:)
You can edit pre-build and post-build events by: Right-clicking on a project -> Properties
-> Build Events
.
I used a utility called RXFIND, it's free and can replace a string within selected files using a RegEx
regular expression.
Here's the command line I'm using:
"$(SolutionDir)ThirdParty\rxfind\rxfind.exe" "$(ProjectDir)Resources\*.Designer.cs" "/P:internal " "/R:public " /Q /B:2
Please note, that all my resources are located under Resource directory within each project and the command line utility resides in \ThirdParty\rxfind
directory
I also have the same error. To solve the problem I just created a public class
that inherits from the class representing the resources file, knowing that it must also be public class this is my exep:
public class TrackResourceWrapper : TrackResource
{
}
with:
TrackResourceWrapper
is inheriting class
TrackResource
is the class which is located in the code resource file behind (public class)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With