views:

177

answers:

1

Hello,

I've got two projects in WPF and one project is the main one and the second one is just for testing (it uses files of the main project - files are added via Project -> add -> Existing items... -> selected file -> add as link so that the file is only in the main project really).

Folders with projects are these:

C:\Work\...\Projects\Main
C:\Work\...\Projects\XXXTestProject

where XXX stands for different parts of the Main project which I test separately.

I've got the code:

<Window x:Class="Sokoban.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Sokoban"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Window1" Height="559" Width="419">
    <Window.Resources>        
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="GameDesk.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Grid>        
        <Rectangle local:GameDeskProperties.FieldSize="30" Name="myrect" Style="{DynamicResource GameDesk}" MouseEnter="Rectangle_MouseEnter" />
    </Grid>
</Window>

... which should use XAML resources from GameDesk.xaml which is in the main project and it seems that I can't use Pack URI (http://msdn.microsoft.com/en-us/library/aa970069.aspx). How can I specify the file?

  • Should I use absolute path? (C:\Work...\Main\Resources\GameDesk.xaml)

  • Or is there any other way?

Thank you for help!

+1  A: 

MSDN link here

Use a pack:// URI of the form:

pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml

if the XAML is in a referenced assembly

or

pack://siteoforigin:,,,/Subfolder/SiteOfOriginFile.xaml

if the XAML is loose and copied to the bin folder.

Danny Varod
I want to use the first option but I don't think it can work in my case because I don't have these two projects under one solution. Both projects are in separated solution. How would it exactly look like in my scenario? Thank you!
MartyIX
Doesn't have to be in the same solution, just add a reference to the DLL.
Danny Varod
But if it has to be compiled ("reference to the DLL") than I can't make changes in test project (which effectively means in main project). So far I've set the pre-build event in VS which copies the needed file which is not a nice solution but it works and copy is done via relative paths so that it remains portable.
MartyIX
You can add a reference to a DLL in your bin or add a reference path. - This is not a problem and not WPF related - just a common .NET reference path issue that is solvable.
Danny Varod
If you do the reference correctly, When the DLL is updated the reference is updated.
Danny Varod
In the project options add a reference path, it is saved in the projectname.username.csproj.user file, copy the XML to the projectname.csproj file and the you can edit the XML to add parameters e.g. $(Platform), $(Configuration) and even set copylocal=true and remove the build event (just make sure the specificversion=false).
Danny Varod