Hello, and thank you in advance for your help.
I am attempting to have a a column that would change the way it displays data based off an enum value in another column using MVVM. For a reason I have not been able to find, there are two issues happening.
My column that has different data types displaying has a stackpanel that contains three bound objects, a textbox, textblock, and bool. On each of these is a converter that will refer to the Enum where the logic will set one to visible and the other two to collapsed.
Currently, the binding is working, but the only way to see the value is to click on the field. Also, only one row shows the data, if I select another field the data disappears and shows the new data (and the correct data persists and shows if I click it again). Another problem is that the converter only fires when I click the field, even though it is not bound to a click style event.
Do you have any idea why data is not showing up when unless the boxes are clicked? Do you how to show the data on all rows?
Here is my code:
Xaml:
<telerik:GridViewColumn Header="Action" Width="150">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadComboBox ItemsSource="{Binding Path=ActionSource}"
SelectedValue="{Binding Path=Action}"
DisplayMemberPath="Description"
SelectedValuePath="Value"
Name="actionBox" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
<telerik:GridViewColumn Header="Value" Width="*">
<telerik:GridViewColumn.CellEditTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=RenamedName, Mode=TwoWay}"
cal:Bind.Model="{Binding}"
IsReadOnly="False"
Visibility="{Binding Path=Action, Converter={StaticResource MappableTypesIndexToBoolConverter}, ConverterParameter=Renamed}" />
<TextBlock Text="{Binding Path=Ignore, Mode=OneWay}"
cal:Bind.Model="{Binding}"
Visibility="{Binding Path=Action, Converter={StaticResource MappableTypesIndexToBoolConverter}, ConverterParameter=Ignore}" />
<telerik:RadComboBox ItemsSource="{Binding Path=MappableComponentName, Mode=TwoWay}"
SelectedItem="{Binding Path=Remapped, Mode=TwoWay}"
DisplayMemberPath="Name"
DropDownWidth="auto"
cal:Bind.Model="{Binding}"
Visibility="{Binding Path=Action, Converter={StaticResource MappableTypesIndexToBoolConverter}, ConverterParameter=Map}"
Width="200" />
</StackPanel>
</DataTemplate>
</telerik:GridViewColumn.CellEditTemplate>
</telerik:GridViewColumn>
Converter:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string actionsBoxValue = value.ToString();
string param = parameter.ToString();
switch (actionsBoxValue)
{
case "IGNORE":
if (param == "Ignore")
{
return "Visible";
}
else
{
return "Collapsed";
}
case "RENAMED":
if (param == "Renamed")
{
return "Visible";
}
else
{
return "Collapsed";
}
case "MAP":
if (param == "Map")
{
return "Visible";
}
else
{
return "Collapsed";
}
case "CREATE":
{
if (param == "Create")
{
return "Visible";
}
else
{
return "Collapsed";
}
}
default:
return null;
}
}
Let me know if there is any additional information that might be helpful. Have a great day!