Back to Devexpress

TreeListView.NodeImageSelector Property

wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-c000f98b.md

latest5.0 KB
Original Source

TreeListView.NodeImageSelector Property

Gets or sets a selector that chooses a node image based on custom logic. This is a dependency property.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public TreeListNodeImageSelector NodeImageSelector { get; set; }
vb
Public Property NodeImageSelector As TreeListNodeImageSelector

Property Value

TypeDescription
DevExpress.Xpf.Grid.TreeListNodeImageSelector

A DevExpress.Xpf.Grid.TreeListNodeImageSelector descendant that chooses a node image based on custom logic.

|

Remarks

Run Demo: End-User Customization

The following code sample demonstrates how to use the NodeImageSelector to display different images based on the node level:

xaml
<Window.Resources>
    <local:EmployeeTaskImageSelector x:Key="taskImageSelector"/>  
</Window.Resources>
<Grid>
    <dxg:TreeListControl ...>
        <!-- ... -->
        <dxg:TreeListControl.View>
            <dxg:TreeListView ...
                              ShowNodeImages="True"
                              NodeImageSelector="{StaticResource taskImageSelector}">                   
            </dxg:TreeListView>
        </dxg:TreeListControl.View>
    </dxg:TreeListControl>
</Grid>
csharp
public class EmployeeTaskImageSelector : DevExpress.Xpf.Grid.TreeListNodeImageSelector {
    static ImageSource GetSvgImage(string imageName) {
        var extension = new SvgImageSourceExtension() { 
            Uri = new Uri(string.Format("pack://application:,,,/IsReadOnlyBindingExample;component/Images/{0}.svg", imageName)), 
            Size = new System.Windows.Size(16, 16)
        };
        return (ImageSource)extension.ProvideValue(null);
    }
    static List<ImageSource> TaskImages;
    static EmployeeTaskImageSelector() {
        TaskImages = new List<ImageSource>();
        TaskImages.Add(GetSvgImage("Task"));
        TaskImages.Add(GetSvgImage("Note"));
    }
    public override ImageSource Select(TreeListRowData rowData) {
        if(rowData.Level == 0)
            return TaskImages[0];
        return TaskImages[1];
    }
}
vb
Public Class EmployeeTaskImageSelector
  Inherits DevExpress.Xpf.Grid.TreeListNodeImageSelector

  Private Shared Function GetSvgImage(ByVal imageName As String) As ImageSource
    Dim extension = New SvgImageSourceExtension() With {
      .Uri = New Uri(String.Format("pack://application:,,,/IsReadOnlyBindingExample;component/Images/{0}.svg", imageName)),
      .Size = New System.Windows.Size(16, 16)
    }
    Return CType(extension.ProvideValue(Nothing), ImageSource)
  End Function

  Private Shared TaskImages As List(Of ImageSource)
  Shared Sub New()
    TaskImages = New List(Of ImageSource)()
    TaskImages.Add(GetSvgImage("Task"))
    TaskImages.Add(GetSvgImage("Note"))
  End Sub
  Public Overrides Function [Select](ByVal rowData As TreeListRowData) As ImageSource
    If rowData.Level = 0 Then
      Return TaskImages(0)
    End If
    Return TaskImages(1)
  End Function
End Class

Note

An image specified by the TreeListNode.Image property takes priority over an image specified by the NodeImageSelector.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the NodeImageSelector property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-grid-read-only-and-enabled-binding/CS/MainWindow.xaml#L47

xml
ShowNodeImages="True"
NodeImageSelector="{StaticResource taskImageSelector}"
UseLegacyFilterPanel="False">

See Also

ShowNodeImages

ImageFieldName

Image

TreeListView Class

TreeListView Members

DevExpress.Xpf.Grid Namespace