开发者

How to specify path for file from different project in WPF?

开发者 https://www.devze.com 2022-12-25 16:02 出处:网络
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... -> sel

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>
     开发者_JAVA技巧           <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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号