How to close dropDownButton as a celltemplate on a grid cell

3 posts, 0 answers
  1. Grr
    Grr avatar
    9 posts
    Member since:
    Sep 2010

    Posted 06 Dec 2010 Link to this post

    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. Grr
    Grr avatar
    9 posts
    Member since:
    Sep 2010

    Posted 07 Dec 2010 Link to this post

    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??



  3. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 09 Dec 2010 Link to this post

    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
Back to Top