Skip to content

Instantly share code, notes, and snippets.

@bogdanbujdea
Created May 16, 2013 21:37
Show Gist options
  • Select an option

  • Save bogdanbujdea/5595300 to your computer and use it in GitHub Desktop.

Select an option

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}}" />
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