Click here to Skip to main content
15,437,758 members
Home / Discussions / WPF
   

WPF

 
Questionunable to access parent property from a Trigger Pin
George Nistor13-Mar-12 7:15
MemberGeorge Nistor13-Mar-12 7:15 
Hi I needed a custom ComboBox control with a DataGrid as popup. I managed to change the MSDN example and everything works except I can't set ComboBox.IsDropDownOpen property from the
Trigger.
It it usefull also for setting ComboBox.Text property with the text selected from the DataGrid.

The problem is at the end near comments:
Property="ComboBox.IsDropDownOpen" Value="False"
(this line does not have any affect because the comboBox is not identified by name or style type).

Somehow I need to specify the comboBox style..

Any ideas how to do it?

RelativeSource with TemplateParent..

<pre lang="HTML">
<Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBox">
                        <Grid>
                            <ToggleButton 
            Name="ToggleButton" 
            Template="{StaticResource ComboBoxToggleButton}" 
            Grid.Column="2" 
            Focusable="false"
            IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
            ClickMode="Press">
                            </ToggleButton>
                            <ContentPresenter
            Name="ContentSite"
            IsHitTestVisible="False" 
            Content="{TemplateBinding SelectionBoxItem}"
            ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
            ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
            Margin="3,3,23,3"
            VerticalAlignment="Center"
            HorizontalAlignment="Left" />
                            <TextBox x:Name="PART_EditableTextBox"
            Style="{x:Null}" 
            Template="{StaticResource ComboBoxTextBox}" 
            HorizontalAlignment="Left" 
            VerticalAlignment="Center" 
            Margin="3,3,23,3"
            Focusable="True" 
            Background="Transparent"
            Visibility="Hidden"
            IsReadOnly="{TemplateBinding IsReadOnly}"/>
            <Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
               <Grid   Name="DropDown"  SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}"  MaxHeight="{TemplateBinding MaxDropDownHeight}">
                                    <Border 
                x:Name="DropDownBorder"
                Background="{StaticResource WindowBackgroundBrush}"
                BorderThickness="1"
                BorderBrush="{StaticResource SolidBorderBrush}"/>
              
                                    <DataGrid
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                            ItemsSource="{TemplateBinding ItemsSource}"
                                            AutoGenerateColumns="False"
                                            IsReadOnly="True"
                                        GridLinesVisibility="None"
                                        Background="LightGray" 
                                        RowBackground="LightBlue"
                                        AlternatingRowBackground="LightCyan"
                                        SelectedItem="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=SelectedIndex}">
                                        <DataGrid.Columns>
                                            <DataGridTextColumn
                                                    Header="Name"
                                                    MinWidth="150"    
                                                    Binding="{Binding Path=Name}"/>
                                            <DataGridTextColumn
                                                    Header="Address"
                                                    MinWidth="200"   
                                                    Binding="{Binding Path=Address}"/>
                                        </DataGrid.Columns>

                                        <DataGrid.CellStyle>
                                            <Style TargetType="DataGridCell">
                                                <Style.Triggers>
                                                    <Trigger Property="IsSelected"  Value="True">
                                                        <!-- try to access directly parrent property-->
                                                        
                                                        <Setter Property="ComboBox.IsDropDownOpen" Value="False"/>
                                                    </Trigger>
                                                </Style.Triggers>
                                            </Style>

QuestionBinding Fill property to value of node with particular id in XML Pin
Mahesha99912-Mar-12 21:32
MemberMahesha99912-Mar-12 21:32 
Questioninteraction between Models in PRISM V4 (WPF) Pin
radhwane12-Mar-12 13:09
Memberradhwane12-Mar-12 13:09 
Questiondefining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey12-Mar-12 3:37
MemberSutton Mehaffey12-Mar-12 3:37 
AnswerRe: defining a grid row within a grid column, wpf, c# Pin
Pete O'Hanlon12-Mar-12 3:42
mvaPete O'Hanlon12-Mar-12 3:42 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey12-Mar-12 4:50
MemberSutton Mehaffey12-Mar-12 4:50 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey12-Mar-12 4:51
MemberSutton Mehaffey12-Mar-12 4:51 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey12-Mar-12 4:52
MemberSutton Mehaffey12-Mar-12 4:52 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Pete O'Hanlon12-Mar-12 4:59
mvaPete O'Hanlon12-Mar-12 4:59 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey12-Mar-12 5:15
MemberSutton Mehaffey12-Mar-12 5:15 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Pete O'Hanlon12-Mar-12 5:22
mvaPete O'Hanlon12-Mar-12 5:22 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey12-Mar-12 5:32
MemberSutton Mehaffey12-Mar-12 5:32 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey12-Mar-12 15:33
MemberSutton Mehaffey12-Mar-12 15:33 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Pete O'Hanlon12-Mar-12 22:32
mvaPete O'Hanlon12-Mar-12 22:32 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Sutton Mehaffey13-Mar-12 2:52
MemberSutton Mehaffey13-Mar-12 2:52 
GeneralRe: defining a grid row within a grid column, wpf, c# Pin
Pete O'Hanlon13-Mar-12 3:11
mvaPete O'Hanlon13-Mar-12 3:11 
QuestionSliver light Pin
mehul_porject11-Mar-12 19:32
Membermehul_porject11-Mar-12 19:32 
AnswerRe: Sliver light Pin
Abhinav S11-Mar-12 19:56
MemberAbhinav S11-Mar-12 19:56 
QuestionMVVM Master-Details project Pin
Geysser10-Mar-12 23:41
MemberGeysser10-Mar-12 23:41 
AnswerRe: MVVM Master-Details project Pin
Abhinav S11-Mar-12 19:57
MemberAbhinav S11-Mar-12 19:57 
AnswerRe: MVVM Master-Details project Pin
Mycroft Holmes11-Mar-12 21:21
professionalMycroft Holmes11-Mar-12 21:21 
GeneralRe: MVVM Master-Details project Pin
Geysser11-Mar-12 23:28
MemberGeysser11-Mar-12 23:28 
GeneralRe: MVVM Master-Details project Pin
Mycroft Holmes12-Mar-12 1:07
professionalMycroft Holmes12-Mar-12 1:07 
GeneralRe: MVVM Master-Details project Pin
Geysser12-Mar-12 2:43
MemberGeysser12-Mar-12 2:43 
GeneralRe: MVVM Master-Details project Pin
Pete O'Hanlon12-Mar-12 1:23
mvaPete O'Hanlon12-Mar-12 1:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.