Dela via


Control.ElementSoundMode Property

Definition

Get or sets a value that specifies a control's preference for whether sounds are played.

public:
 property ElementSoundMode ElementSoundMode { ElementSoundMode get(); void set(ElementSoundMode value); };
ElementSoundMode ElementSoundMode();

void ElementSoundMode(ElementSoundMode value);
public ElementSoundMode ElementSoundMode { get; set; }
var elementSoundMode = control.elementSoundMode;
control.elementSoundMode = elementSoundMode;
Public Property ElementSoundMode As ElementSoundMode
<control ElementSoundMode="elementSoundModeMemberName"/>

Property Value

A value of the enumeration that specifies a control's preference for whether sounds are played. The default is Auto.

Windows requirements

Device family
Windows 10 Anniversary Edition (introduced in 10.0.14393.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v3.0)

Remarks

Set the ElementSoundMode property to override the global ElementSoundPlayer setting for a specific control.

For more info about using this property, see Sound in UWP apps.

Version compatibility

The ElementSoundMode property is not available prior to Windows 10, version 1607. If your app’s 'minimum platform version' setting in Microsoft Visual Studio is less than the 'introduced version' shown in the Requirements block later in this page, you must design and test your app to account for this. For more info, see Version adaptive code.

To avoid exceptions when your app runs on previous versions of Windows 10, do not set this property in XAML or use it without performing a runtime check. This example shows how to use the ApiInformation class to check for the presence of this property before you set it.

 private void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
    if (ApiInformation.IsPropertyPresent("Windows.UI.Xaml.Controls.Control", "ElementSoundMode"))
    {
        button1.ElementSoundMode = ElementSoundMode.Off;
    }
}

Applies to

See also