buttons
这是xaml 中媒体元素的三个标准:
<Button Content="Sound1"
Click="Button_Click1"
HorizontalAlignment="Center"
VerticalAlignment="Top"/>
<MediaElement x:Name="PlaySound1"
Grid.Row="1"
/>
<Button Content="Sound2"
Click="Button_Click2"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="177,72,177,0"
Width="126"/>
<MediaElement x:Name="PlaySound2"
Grid.Row="1"
/>
<Button Content="Sound3"
Click="Button_Click3"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Margin="177,149,177,0"
Width="126" />
<MediaElement x:Name="PlaySound3"
Grid.Row="1"
/>
这是我使用的简单代码,当我尝试播放第三个按钮时,它不起作用,我单击了buttons
所有组合(首先是button2
、button3 和button1
)但它不起作用。
private void Button_Click1(object sender, RoutedEventArgs e)
{
PlaySound1.Source = new Uri("sound.wma", UriKind.Relative);
PlaySound1.Stop();
PlaySound1.Play();
}
private void Button_Click2(object sender, RoutedEventArgs e)
{
PlaySound2.Source = new Uri("sound2.wma", UriKind.Relative);
PlaySound2.Stop();
PlaySound2.Play();
}
private void Button_Click3(object sender, RoutedEventArgs e)
{
PlaySound3.Source = new Uri("sound3.wma", UriKind.Relative);
PlaySound3.Stop();
PlaySound3.Play();
}
使用具有多种声音的多个按钮的正确方法是什么?