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

How to close dropDownButton as a celltemplate on a grid cell

2 Answers 90 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Grr
Top achievements
Rank 1
Grr asked on 06 Dec 2010, 06:49 PM
My Scenario is I have a dropdown button as a cell template in a radGrid. where the drop down content is a color picker.
In the code I only get the handle to the radColor picker. How can I close the dropDown.
   <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadDropDownButton Background="{Binding Path=ColorBrush, Mode=TwoWay}" 
                                                       Width="20" Height="15" DropDownWidth="187" CornerRadius="3" 
                                                       DropDownIndicatorVisibility="Collapsed">
                                <telerik:RadDropDownButton.DropDownContent>
                                    <telerik:RadColorSelector 
                                        SelectedColor="{Binding Path=ColorBrush, Mode=TwoWay}" 
                                        SelectedColorChanged="RadColorPicker_SelectedColorChanged"/>
                                </telerik:RadDropDownButton.DropDownContent>
                            </telerik:RadDropDownButton>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>

 private void RadColorPicker_SelectedColorChanged(object sender, EventArgs e)
        {
            Control ctrl = (sender as RadColorSelector).Parent as Control;
        }

2 Answers, 1 is accepted

Sort by
0
Grr
Top achievements
Rank 1
answered on 07 Dec 2010, 07:33 PM
I did not hear from anybody. So more details

I am trying to put color picker in the radButton dropdown content and keep it in cell template of a cell.

Here is xaml.
 
<telerik:GridViewDataColumn Header="Color"
                                            x:Name="Color"
                                            DataMemberBinding="{Binding Path=ColorBrush, Mode=TwoWay}"
                                            Width="40"
                                            UniqueName="Color">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadDropDownButton Background="{Binding Path=ColorBrush, Mode=TwoWay}"  Name="ColorDropDown1"
                                                       Width="20" Height="15" DropDownWidth="187" CornerRadius="3" 
                                                       DropDownIndicatorVisibility="Collapsed" >
                                <telerik:RadDropDownButton.DropDownContent>
                                    <telerik:RadColorSelector 
                                        SelectedColor="{Binding Path=ColorBrush, Mode=TwoWay}" 
                                        SelectedColorChanged="RadColorPicker_SelectedColorChanged"/>
                                </telerik:RadDropDownButton.DropDownContent>
                            </telerik:RadDropDownButton>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>

What happens is when I click on color, I need to close the drop down. What I am not getting is how to get the handle to ColorDropDown1. To say IsOpen=false.

I tried something like this in code.
 private void RadColorPicker_SelectedColorChanged(object sender, EventArgs e)
        {
            (mRadGridView.SelectedItem as ChannelProperty).ColorBrush = new SolidColorBrush((sender as RadColorSelector).SelectedColor);
            RadDropDownButton button = FindVisualChildByName<RadDropDownButton>(this"ColorDropDown1");
            button.IsOpen = false;
        }

        private static T FindVisualChildByName<T>(DependencyObject parent, string name) where T : DependencyObject
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
            {
                var child = VisualTreeHelper.GetChild(parent, i);
                string controlName = child.GetValue(Control.NameProperty) as string;
                if (controlName == name)
                {
                    return child as T;
                }
                else
                {
                    T result = FindVisualChildByName<T>(child, name);
                    if (result != null)
                        return result;
                }
            }
            return null;
        }
This did not seem to help me. Any help??



0
Tina Stancheva
Telerik team
answered on 09 Dec 2010, 04:22 PM
Hi Giri,

Please have a look at the attached sample application and let us know if this is close to what you had in mind.

Regards,
Tina Stancheva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
Buttons
Asked by
Grr
Top achievements
Rank 1
Answers by
Grr
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or