DirectoryNotFoundException从XAML文件读取时的Windows Phone

时间:2014-05-02 19:03:51

标签: c# xaml windows-phone-8 windows-phone

我想从XAML文件中读取数据,但我得到了一个例外。我确定我在这条路上有这个文件。之前我还使用SampleData.xaml来绑定数据以查看设计的外观,现在我想在运行时读取相同的数据。

SoundModel soundModel = XamlReader.Load(new StreamReader("SampleData/SampleData.xaml").ReadToEnd()) as SoundModel;

消息:

An exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code .
   Additional information: Could not find a part of the path 'C:\Data\Programs\{7AD01B6A-254F-4161-8CC1-E2D338FD6E69}\Install\SampleData\SampleData.xaml'.

SampleData.xaml:

<vm:SoundModel
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vm="clr-namespace:SoundBoard.ViewModels">

    <vm:SoundModel.Animals>
        <vm:SoundGroup Title="Animals Sample">
            <vm:SoundGroup.Items>
                <vm:SoundData Title="Animals 1" FilePath="Animals.wav" />
            </vm:SoundGroup.Items>
        </vm:SoundGroup>
    </vm:SoundModel.Animals>

    <vm:SoundModel.Cartoons>
        <vm:SoundGroup Title="Cartoons Sample">
            <vm:SoundGroup.Items>
                <vm:SoundData Title="Cartoons 1" FilePath="Cartoons.wav" />
                <vm:SoundData Title="Cartoons 2" FilePath="Cartoons.wav" />
            </vm:SoundGroup.Items>
        </vm:SoundGroup>
    </vm:SoundModel.Cartoons>

    <vm:SoundModel.Taunts>
        <vm:SoundGroup Title="Taunts Sample">
            <vm:SoundGroup.Items>
                <vm:SoundData Title="Taunts 1" FilePath="Taunts.wav" />
                <vm:SoundData Title="Taunts 2" FilePath="Taunts.wav" />
                <vm:SoundData Title="Taunts 3" FilePath="Taunts.wav" />
            </vm:SoundGroup.Items>
        </vm:SoundGroup>
    </vm:SoundModel.Taunts>

    <vm:SoundModel.Warnings>
        <vm:SoundGroup Title="Warnings Sample">
            <vm:SoundGroup.Items>
                <vm:SoundData Title="Warnings 1" FilePath="Warnings.wav" />
                <vm:SoundData Title="Warnings 2" FilePath="Warnings.wav" />
                <vm:SoundData Title="Warnings 3" FilePath="Warnings.wav" />
                <vm:SoundData Title="Warnings 4" FilePath="Warnings.wav" />
            </vm:SoundGroup.Items>
        </vm:SoundGroup>
    </vm:SoundModel.Warnings>

    <vm:SoundModel.CustomSounds>
        <vm:SoundGroup Title="Custom">
            <vm:SoundGroup.Items>
                <vm:SoundData Title="Custom 1" FilePath="Custom.wav" />
                <vm:SoundData Title="Custom 2" FilePath="Custom.wav" />
                <vm:SoundData Title="Custom 3" FilePath="Custom.wav" />
                <vm:SoundData Title="Custom 4" FilePath="Custom.wav" />
            </vm:SoundGroup.Items>
        </vm:SoundGroup>
    </vm:SoundModel.CustomSounds>

</vm:SoundModel>

SoundModel包含:

public SoundGroup CustomSounds { get; set; }
public SoundGroup Animals { get; set; }
public SoundGroup Cartoons { get; set; }
public SoundGroup Taunts { get; set; }
public SoundGroup Warnings { get; set; }

0 个答案:

没有答案