Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum StateValue { Player, Wall, Box }
- enum StateColor { Colors.Red, Colors.Grey, Colors.Brown }
- <Button Content="Player" Background="{Binding Source=...?}" />
- public Dictionary<StateValue, Color> stateValueColor =
- new Dictionary<ElementState, Color>()
- {
- { StateValue.Player, Colors.Red },
- { StateValue.Wall, Colors.Grey },
- { StateValue.Box, Colors.Brown }
- };
- [ValueConversion(typeof(StateValue), typeof(Color))]
- public class StateValueColorConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if(!(value is StateValue))
- throw new ArgumentException("value not of type StateValue");
- StateValue sv = (StateValue)value;
- //sanity checks
- switch (sv)
- {
- case StateValue.Player:
- return Colors.Red;
- //etc
- }
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- Color c = (value as Color);
- if(c == Colors.Red)
- return StateValue.Player;
- //etc
- }
- }
- <Button
- Content="Player"
- Background="{Binding Source=StateValue,
- Converter={StaticResource stateValueColorConverter}}" />
Add Comment
Please, Sign In to add comment