Created
June 8, 2012 05:57
-
-
Save jhalbrecht/2893863 to your computer and use it in GitHub Desktop.
A value converter I used for a Callisto rating
This file contains 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
using System; | |
using Windows.UI.Xaml.Data; | |
/* | |
xmlns:callisto="using:Callisto.Controls" | |
xmlns:lm="using:yaLolFx.Models" | |
<Page.Resources> | |
<lm:ConverterRatingMultiplier x:Key="RatingMultiplier" /> | |
</Page.Resources> | |
<callisto:Rating x:Name="StarRating" | |
ItemCount="5" | |
Value="{Binding AverageStarRating, Converter={StaticResource RatingMultiplier}}" /> | |
*/ | |
namespace yaLolFx.Models | |
{ | |
public class ConverterRatingMultiplier : IValueConverter | |
{ | |
public object Convert(object value, Type targetType, object parameter, string language) | |
{ | |
return ofMap((int)value, 0, 5, 0.1f, 1); | |
} | |
public object ConvertBack(object value, Type targetType, object parameter, string language) | |
{ | |
throw new NotImplementedException(); | |
} | |
// grabed this from openframeworks.cc Note: openframeworks is cool! originall c++ | |
// tried to check http://www.codecodex.com/wiki/Main_Page couldn't figure out | |
// what to call this range map to search for and see other examples. | |
// this is imperfect, but working. :-) | |
float ofMap(float value, float inputMin, float inputMax, float outputMin, float outputMax) | |
{ | |
return ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment