Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight resource constructor always return to internal

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>
like image 917
Cédric Boivin Avatar asked Oct 19 '10 18:10

Cédric Boivin


4 Answers

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

like image 184
Gavin Avatar answered Nov 07 '22 02:11

Gavin


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!

like image 22
Alex B Avatar answered Nov 07 '22 03:11

Alex B


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

like image 27
michal Avatar answered Nov 07 '22 04:11

michal


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)

like image 25
ANADI Juba Avatar answered Nov 07 '22 03:11

ANADI Juba