2

を使用して ResourceDictionary としてロードする XAML ファイルがあります。

using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    // Read in ResourceDictionary File
                    ResourceDictionary dic =
                       (ResourceDictionary)XamlReader.Load(fs);

                    // Clear any previous dictionaries loaded
                    Application.Current.Resources.MergedDictionaries.Clear();
                    // Add in newly loaded Resource Dictionary
                    Application.Current.Resources.MergedDictionaries.Add(dic);
                    fs.Close();
                }

その XAML 内に、ImageBrush があります。辞書を読んでみると、MyApplication.vshost.exe は ImageBrush を構成する画像ファイルを使用しているようです。つまり、ImageBrush の Source プロパティにあるファイルです。そのファイルを削除する必要がありますが、ファイルが別のプロセスで使用されているため、エラーが発生します。私の質問は、後でファイルを自由に削除できるように、これを適切に行う方法です。

4

1 に答える 1

2

次のように記述して、リソースにBitmapCacheOption.OnLoadaを設定できます。BitmapImageImageBrush

<ImageBrush x:Key="myImageBrush">
    <ImageBrush.ImageSource>
        <BitmapImage UriSource="..." CacheOption="OnLoad"/>
    </ImageBrush.ImageSource>
</ImageBrush>
于 2014-07-17T11:22:18.400 に答える