Click here to Skip to main content
15,909,440 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF - Understanding Binding Syntax Pin
Kevin Marois20-Aug-13 8:29
professionalKevin Marois20-Aug-13 8:29 
I am working with a datagrid with a combobox, and it took me 3 hours to get it working, and that's only after I stumbled across an example.

So now I have this:

<DataGrid Grid.Row="1"
           Grid.Column="0"
           ItemsSource="{Binding JobPhases}"
           SelectedItem="{Binding SelectedJobPhase}"
           SelectionMode="Single"
           SelectionUnit="Cell"
           CanUserAddRows="False"
           CanUserReorderColumns="False"
           CanUserResizeColumns="True"
           CanUserResizeRows="False"
           CanUserSortColumns="True"
           AutoGenerateColumns="False"
           AlternatingRowBackground="Gainsboro"
           IsSynchronizedWithCurrentItem="True"
           AlternationCount="2"
           FontSize="12"
           IsReadOnly="False"
           FontWeight="Normal"
           FontStyle="Normal">

     <DataGrid.Columns>

         <DataGridComboBoxColumn Header="Phase Type"
                                 SelectedItemBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedJobPhaseType}"
                                 DisplayMemberPath="Caption"
                                 Width="150">

             <DataGridComboBoxColumn.EditingElementStyle>
                 <Style TargetType="{x:Type ComboBox}">
                     <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.JobPhaseTypes}"/>
                     <Setter Property="IsReadOnly" Value="True"/>
                     <Setter Property="StaysOpenOnEdit" Value="True" />
                 </Style>
             </DataGridComboBoxColumn.EditingElementStyle>

             <DataGridComboBoxColumn.ElementStyle>
                 <Style TargetType="{x:Type ComboBox}">
                     <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.JobPhaseTypes}"/>
                 </Style>
             </DataGridComboBoxColumn.ElementStyle>

         </DataGridComboBoxColumn>

     </DataGrid.Columns>

 </DataGrid>


The question I have is - can someone explain the syntax in the binding part?

What does 'RelativeSource' mean, and 'FindAncestor' and 'AncestorType'??

Many thanks!
If it's not broken, fix it until it is

AnswerRe: WPF - Understanding Binding Syntax Pin
Mycroft Holmes20-Aug-13 12:52
professionalMycroft Holmes20-Aug-13 12:52 
GeneralRe: WPF - Understanding Binding Syntax Pin
Kevin Marois20-Aug-13 15:05
professionalKevin Marois20-Aug-13 15:05 
GeneralRe: WPF - Understanding Binding Syntax Pin
Mycroft Holmes20-Aug-13 15:37
professionalMycroft Holmes20-Aug-13 15:37 
GeneralRe: WPF - Understanding Binding Syntax Pin
Kevin Marois20-Aug-13 17:15
professionalKevin Marois20-Aug-13 17:15 
SuggestionRe: WPF - Understanding Binding Syntax Pin
Richard MacCutchan20-Aug-13 20:17
mveRichard MacCutchan20-Aug-13 20:17 
GeneralRe: WPF - Understanding Binding Syntax Pin
Kevin Marois21-Aug-13 5:23
professionalKevin Marois21-Aug-13 5:23 
QuestionWPF/MVVM DataGrid Set Focus to Cell in Edit Mode Pin
Kevin Marois20-Aug-13 7:46
professionalKevin Marois20-Aug-13 7:46 
AnswerRe: WPF/MVVM DataGrid Set Focus to Cell in Edit Mode Pin
Mycroft Holmes20-Aug-13 12:46
professionalMycroft Holmes20-Aug-13 12:46 
QuestionMaximize and Restore Buttons Pin
MohammedRuman19-Aug-13 22:10
MohammedRuman19-Aug-13 22:10 
AnswerRe: Maximize and Restore Buttons Pin
Jason Gleim27-Aug-13 5:45
professionalJason Gleim27-Aug-13 5:45 
QuestionSliding Panel in Wpf Pin
MohammedRuman19-Aug-13 22:05
MohammedRuman19-Aug-13 22:05 
AnswerRe: Sliding Panel in Wpf Pin
Mycroft Holmes19-Aug-13 22:32
professionalMycroft Holmes19-Aug-13 22:32 
AnswerRe: Sliding Panel in Wpf Pin
Jason Gleim27-Aug-13 5:49
professionalJason Gleim27-Aug-13 5:49 
QuestionSilverlight and Android Application Interaction Pin
SwapnilSinnar18-Aug-13 1:39
SwapnilSinnar18-Aug-13 1:39 
AnswerRe: Silverlight and Android Application Interaction Pin
Mycroft Holmes18-Aug-13 11:50
professionalMycroft Holmes18-Aug-13 11:50 
AnswerRe: Silverlight and Android Application Interaction Pin
Jason Gleim27-Aug-13 5:54
professionalJason Gleim27-Aug-13 5:54 
QuestionHorizontal AND Vertical Virtualizing ItemsControl? Pin
Revolty14-Aug-13 8:03
Revolty14-Aug-13 8:03 
AnswerRe: Are you a WPF guru? Pin
Pete O'Hanlon13-Aug-13 13:13
mvePete O'Hanlon13-Aug-13 13:13 
QuestionHow to confine mouse cursor to inkcanvas? Pin
hmdshr12-Aug-13 10:29
hmdshr12-Aug-13 10:29 
QuestionC!Drag Start and Drag Over Events are not firing in Map control of Silverlight with vb.net Pin
Member 101976818-Aug-13 3:35
Member 101976818-Aug-13 3:35 
QuestionHow to display a Windows in full screen on top of the taskbar in wpf? Pin
dharmaa.m6-Aug-13 2:17
dharmaa.m6-Aug-13 2:17 
AnswerRe: How to display a Windows in full screen on top of the taskbar in wpf? Pin
Mycroft Holmes6-Aug-13 12:48
professionalMycroft Holmes6-Aug-13 12:48 
AnswerRe: How to display a Windows in full screen on top of the taskbar in wpf? Pin
Richard Deeming7-Aug-13 0:57
mveRichard Deeming7-Aug-13 0:57 
Questioncreate hyberlink in string using RichTextBox control in WPF Pin
senthil kumar 2225-Aug-13 0:21
professionalsenthil kumar 2225-Aug-13 0:21 

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.