English 中文(简体)
在没有目录的情况下使用纸浆中纸张。
原标题:Using .wav files in wpf without directory
  • 时间:2012-05-18 05:40:48
  •  标签:
  • wpf
  • wav

Hi I have a wpf application that plays sounds on events such as button click. And the current code I have now plays the sound file, but Ive realized that it has to be in another folder which for example if the user deletes, makes the application pretty much not useable. I was wondering, How could I get a .wav file without creating a whole new folder in the application Release directory. Any ideas? Thanks.

问题回答

If the .wav files is added to your project at the root then marked as content (Right Click on the .wav file and click properties. Then change the build action to content) then it will be copied directly to the root output folder

您可将法典或XAML中的编织物作为相对途径(简单“Myfile.wav”)

我认为,这是你所要求的吗?

如何把file夫的档案放在ll子里?

就在项目上添加文件,在档案中填入右侧,并设置Build Action至 Embedded Resource

之后,你可以把.瓦夫的档案装上溪流,并节省下来,使之与:

private void WriteEmbeddedResourceToFile(string writePath, string assemblyName)
    {
        Assembly asm = Assembly.GetExecutingAssembly();
        Stream s = asm.GetManifestResourceStream(assemblyName);
        if (s != null)
        {
            var file = new byte[s.Length];
            s.Read(file, 0, (int)s.Length);
            File.WriteAllBytes(writePath, file);
            s.Close();
        }
    }

assemblyName (如果你把档案放在一个文件夹中,在此插入文件夹子)。

或者,你可以放弃储蓄,使之解体,并且直接使用溪流:

private byte[] GetEmbeddedResource(string assemblyName)
    {
        Assembly asm = Assembly.GetExecutingAssembly();
        Stream s = asm.GetManifestResourceStream(assemblyName);
        if (s != null)
        {
            var file = new byte[s.Length];
            s.Read(file, 0, (int)s.Length);
            s.Close();
            return file;
        }
    }

然后,在你想要装上档案时,GetEmbeddedResource将归还地下阵列。





相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签