Home Forums WPF controls Xceed DataGrid for WPF How to Data Bind to Item

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #25191 |

    <xcdg:DataGridControl
    x:Name=”incidentListView” Margin=”0,29,0,3″ BorderBrush=”{x:Null}”
    AutoCreateColumns = “true”
    SelectionMode=”Single”
    Loaded=”OnLoaded”
    ScrollViewer.ScrollChanged=”IncidentsListScrollChanged”
    SizeChanged =”AdjustRightColumnWidth”>
    <xcdg:DataGridControl.Columns>
    <xcdg:Column
    FieldName = “ID” Title = “ID”
    DisplayMemberBinding = “{Binding Path=ID}”>
    <xcdg:Column.CellContentTemplate>
    <DataTemplate >
    <StackPanel Orientation = “Horizontal”>
    <Image Name = “Img” Margin=”0,0,5,0″ />
    <TextBlock Style =”{StaticResource ItemFontStyle}” Text=”{Binding}”/>
    </StackPanel>
    <DataTemplate.Triggers>
    <DataTrigger Binding = “{Binding Path=MotorOn}” Value = “True”>
    <Setter Property=”Source” Value=”..\Images\MotorOn.png” TargetName=”Img”/>
    </DataTrigger>
    </DataTemplate.Triggers>
    </DataTemplate>
    </xcdg:Column.CellContentTemplate>
    </xcdg:Column>
    </xcdg:DataGridControl.Columns>
    </xcdg:DataGridControl>

    In the above DataTemplate the Text binding works fine the TriggerBinding understandably does not since context is CellTemplate and not the bound collection. If MotorOn is a column displayed in the DataGridControl, how can I reference it using the DataGridControl’s ItemsSource collection as the source for the binding so that I can reference the MotorOn Property? Any other ideas as to how to approach this in general?

    Thank You

    Imported from legacy forums. Posted by Gregory (had 2455 views)

    User (Old forums)
    Member
    Post count: 23064

    Sorry about indentation in above sample, I used spaces for indentation but they were not preserved. This is probably because the forum uses HTML format. To see the XAML better, you can cut and paste it into an editor.

    Imported from legacy forums. Posted by Gregory (had 203 views)

    User (Old forums)
    Member
    Post count: 23064

    OK I figured it out. The DisplayMemberBinding sets the data context for the cell and I originally had DisplayMemberBinding = “{Binding Path = “MyPath”}” . This restricted the data context for the cell to MyPath.

    Once I changed to DisplayMemberBinding = “{Binding}”, it worked fine.

    Imported from legacy forums. Posted by Gregory (had 3476 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.