Created
May 16, 2013 21:37
-
-
Save bogdanbujdea/5595300 to your computer and use it in GitHub Desktop.
converter from text to AudioType
useful in Windows 8 apps so you can bind something to an AudioType property like this:
<Page.Resources>
<converters:TextToAudioQualityConverter x:Key="TextToAudioQuality"></converters:TextToAudioQualityConverter>
</Page.Resources>
...
<TextBox Text="{Binding Converter={StaticResource TextToAudio}}" />
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TextToAudioProfileConverter : IValueConverter | |
| { | |
| public object Convert(object value, Type targetType, object parameter, string language) | |
| { | |
| AudioType audioType = (AudioType)value; | |
| switch (audioType) | |
| { | |
| case AudioType.Mp3: | |
| return "MP3"; | |
| case AudioType.M4a: | |
| return "M4a"; | |
| case AudioType.WMA: | |
| return "WMA"; | |
| default: | |
| return "MP3"; | |
| } | |
| } | |
| public object ConvertBack(object value, Type targetType, object parameter, string language) | |
| { | |
| var strAudioType = value as string; | |
| if (string.IsNullOrEmpty(strAudioType)) | |
| { | |
| return AudioType.Mp3; | |
| } | |
| switch (strAudioType) | |
| { | |
| case "MP3": | |
| return AudioType.Mp3; | |
| case "M4a": | |
| return AudioType.M4a; | |
| case "WMA": | |
| return AudioType.WMA; | |
| default: | |
| return AudioType.Mp3; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment