Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

different styles for treeview

$
0
0

Hi, I'm trying to find how to set different style for TreeView items. At the first level it should be string (Album name) and at the second - items with image + text (as photo with date). Looks simple, but I read alot of treads here and find only separate snippets which is not work when I try to put it to my code.

As I understand there should be 2 classes (root and leaf) which is connected like bellow:

Public Class ClassBase
Public Property Text() As String
Get
Return m_Text
End Get
Set(value As String)
m_Text = Value
End Set
End Property
Private m_Text As String
End Class

Public Class Class1
Inherits ClassBase
Public Property Text2() As String
Get
Return m_Text2
End Get
Set(value As String)
m_Text2 = value
End Set
End Property
Private m_Text2 As String

Public Property Image2() As Image
Get
Return m_Image2
End Get
Set(value As Image)
m_Image2 = value
End Set
End Property
Private m_Image2 As Image

End Class

After that I need some templates in Resources for the root and leaf in a tree like bellow:

<DataTemplate x:Key="TView">
<Grid d:DesignWidth="110" d:DesignHeight="38">
<Label Content="Label" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="TView2">
<Grid d:DesignWidth="172" d:DesignHeight="60">
<Image HorizontalAlignment="Left" Height="60" VerticalAlignment="Top" Width="100"/>
<Label Content="Label" HorizontalAlignment="Right" VerticalAlignment="Top"/>
</Grid>
</DataTemplate>

And, of course TreeView itself at my Window:

<TreeView HorizontalAlignment="Left" Height="247" Margin="251,10,0,0" VerticalAlignment="Top" Width="208"/>

But after that I have no idea, how to combine it! I understand that it should be binded somehow, but not really understand how. And the second - I not really get, how to fill this kind of tree... Can someone help?


Aleksey


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>