タッチ スクリーンで使用する WPF アプリケーションがあります。アプリケーション全体で、画面上のボタンが押されたときに音を鳴らすように依頼されました。私のアイデアは、これを行うためのスタイルを作成し、アプリにリソース辞書を含めることでした。それは非常にうまく機能します。ただし、このスタイルは別の DLL にあり、メイン アプリケーションでサウンド ファイルのパスを変更したいと考えています (以下の BoutonClickSound Url)。しかし、私はそれを行う方法を見つけることができませんでした。私はいくつかの醜いことを試しました:
System.Windows.Application.Current.Resources.MergedDictionaries[0]["BoutonClickSound"] = new Uri(m_MainVM.ButClickSoundPath);
System.Windows.Application.Current.Resources.MergedDictionaries[0].MergedDictionaries[0]["BoutonClickSound"] = new Uri(m_MainVM.ButClickSoundPath);
しかし、どれも機能していないようです...
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=PresentationFramework"
xmlns:sys="clr-namespace:System;assembly=System">
<sys:Uri x:Key="BoutonClickSound">c:\buttonclick.wav</sys:Uri>
<Style TargetType="{x:Type FrameworkElement}" x:Key="SoundButton">
<Style.Triggers>
<EventTrigger RoutedEvent="PreviewMouseDown">
<SoundPlayerAction x:Name="SoundPlayer" Source="{DynamicResource BoutonClickSound}" />
</EventTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type primitives:Selector}" x:Key="SoundSelectionChange">
<Style.Triggers>
<EventTrigger RoutedEvent="SelectionChanged">
<SoundPlayerAction x:Name="SoundPlayer" Source="{DynamicResource BoutonClickSound}" />
</EventTrigger>
</Style.Triggers>
</Style>
これを行う方法はありますか?
ありがとうございました。