This is a migrated thread and some comments may be shown as answers.

Unexpected Behavior With StackPanel on a Column

1 Answer 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
patrick
Top achievements
Rank 1
patrick asked on 12 Aug 2020, 10:22 PM

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!

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 17 Aug 2020, 08:18 AM

Hello Patrick,

Thank you for the shared code snippet. 

Generally speaking, the RadGridView cells can be in either view or edit mode and only one cell at a time can be edited. When the CellEditTemplate is set, this template will be displayed when the cell is in edit mode. That is why the converter is called when the cell is edited and the DataTemplate is visible only for one row. In order to achieve the desired behavior, you can use the CellTemplate property instead. 

I hope you find this helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Tags
GridView
Asked by
patrick
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or