Created
October 1, 2014 18:06
-
-
Save mrichman/84a05ed7f5d45d897fdc to your computer and use it in GitHub Desktop.
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
[ValueConversion(typeof(InstallerAction), typeof(string))] | |
public class InstallerActionConverter : IValueConverter | |
{ | |
/// <summary> | |
/// Converts a value. | |
/// </summary> | |
/// <param name="value">The value produced by the binding source.</param> | |
/// <param name="targetType">The type of the binding target property.</param> | |
/// <param name="parameter">The converter parameter to use.</param> | |
/// <param name="culture">The culture to use in the converter.</param> | |
/// <returns> | |
/// A converted value. If the method returns null, the valid null value is used. | |
/// </returns> | |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
var installerActions = (InstallerAction[])value; | |
var result = new List<string>(); | |
foreach(var item in installerActions) | |
{ | |
switch (item) | |
{ | |
case InstallerAction.Install: | |
result.Add("Install"); | |
break; | |
case InstallerAction.None: | |
result.Add("None"); | |
break; | |
case InstallerAction.UninstallAll: | |
result.Add("Uninstall All"); | |
break; | |
case InstallerAction.UninstallOne: | |
result.Add("Uninstall One"); | |
break; | |
} | |
} | |
return result; | |
} | |
/// <summary> | |
/// Converts a value. | |
/// </summary> | |
/// <param name="value">The value that is produced by the binding target.</param> | |
/// <param name="targetType">The type to convert to.</param> | |
/// <param name="parameter">The converter parameter to use.</param> | |
/// <param name="culture">The culture to use in the converter.</param> | |
/// <returns> | |
/// A converted value. If the method returns null, the valid null value is used. | |
/// </returns> | |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
var installerActions = (string)value; | |
switch (installerActions) | |
{ | |
case "None": | |
return InstallerAction.None; | |
case "Install": | |
return InstallerAction.Install; | |
case "Uninstall One": | |
return InstallerAction.UninstallOne; | |
case "Uninstall All": | |
return InstallerAction.UninstallAll; | |
default: | |
return InstallerAction.None; | |
} | |
} | |
} |
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
<ListView Name="ListView" ItemsSource="{Binding DatabaseInfos}" VerticalAlignment="Stretch" Margin="10"> | |
<ListView.Resources> | |
<Style TargetType="ListViewItem"> | |
<Style.Triggers> | |
<Trigger Property="Validation.HasError" Value="True"> | |
<Setter Property="Background" Value="Red" /> | |
</Trigger> | |
</Style.Triggers> | |
</Style> | |
</ListView.Resources> | |
<ListView.View> | |
<GridView> | |
<GridViewColumn Header="Action"> | |
<GridViewColumn.CellTemplate> | |
<DataTemplate> | |
<ComboBox Width="100" ItemsSource="{Binding Source={StaticResource ActionFromEnum}, Converter={StaticResource InstallerActionConverter}}" SelectedItem="{Binding Action}" /> | |
</DataTemplate> | |
</GridViewColumn.CellTemplate> | |
</GridViewColumn> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment