I currently have a Loop going through a cube which returns the name (Caption) of its items.
However as this is an OLAP cube I want to distinguish between user defined and attribute hierarchies. I thought the best way to do this would be to give each one a different color (so give User Defined Hierarchies a blue font and Attribute Hierarchies a red font for example).
I thought this would be simple but the method I tried below threw alot of errors, while other methods turned all of the items a particular colour rather than just the items I wanted.
Has anyone got an idea of how I could change an items colour depending on its value??
Window1.xaml.cs
foreach (Hierarchy hierarchy in dimension.Hierarchies)
{
Dimension HierarchyItem = new Dimension();
HierarchyItem.Caption = hierarchy.Caption;
DimensionItem.SubDimensions.Add(HierarchyItem);
HierarchyItem.IsDraggable = true;
if (HierarchyItem.Caption == "Account Number")
HierarchyItem.Caption = Brushes.Red)
else if (HierarchyItem.Caption == "Customer Number")
HierarchyItem.Caption = Brushes.Blue)
4 Answers, 1 is accepted
0
Hello James,
You can have an observable Brush property on your business class, say
public Brush TitleBrush { ... }
Then in the TreeView's ItemTemplate (the HierarchicalDataTemplate) you can bind the Foreground of the TextBlock there to this property:
Foreground="{Binding TileBrush}"
Does this work for you?
All the best,
Miroslav
the Telerik team
You can have an observable Brush property on your business class, say
public Brush TitleBrush { ... }
Then in the TreeView's ItemTemplate (the HierarchicalDataTemplate) you can bind the Foreground of the TextBlock there to this property:
Foreground="{Binding TileBrush}"
Does this work for you?
All the best,
Miroslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
James
Top achievements
Rank 1
answered on 17 Aug 2010, 10:17 AM
Nearly, but I still get an error.....
HierarchyItem.TitleBrush.Add(TitleBrush)
I am still trying to get the colour of the text to change depending on its text value (Caption) but it tells me that I cannot convert the observable collection to media brush.
Am I just missing something simple??
Regards
James
Window1.xaml
HierarchyItem.TitleBrush.Add(TitleBrush)
I am still trying to get the colour of the text to change depending on its text value (Caption) but it tells me that I cannot convert the observable collection to media brush.
Am I just missing something simple??
Regards
James
Window1.xaml
<Window.Resources>
<HierarchicalDataTemplate x:Key=
"ColorTemplate"
ItemsSource =
"{Binding TitleBrush}"
>
<TextBlock Foreground=
"{Binding TitleBrush}"
/>
</HierarchicalDataTemplate>
</Window.Resources>
Cube.cs
Window1.xaml.cs
public
class
Dimension
{
private
string
_caption;
private
string
_uniqueName;
public
Dimension()
{
this
.TitleBrush =
new
ObservableCollection<TitleBrush>();
}
public
ObservableCollection<TitleBrush> TitleBrush
{
get
;
set
;
}
public class TitleBrush
{
private object _brush;
public object Brush
{
get { return _brush; }
set { _brush = value; }
}
}
Window1.xaml.cs
foreach
(Hierarchy hierarchy
in
dimension.Hierarchies)
{
Dimension HierarchyItem =
new
Dimension();
HierarchyItem.Caption = hierarchy.Caption;
HierarchyItem.UniqueName = hierarchy.UniqueName;
DimensionItem.SubDimensions.Add(HierarchyItem);
HierarchyItem.IsDraggable =
true
;
if
(HierarchyItem.Caption ==
"Account Number"
)
{
ObservableCollection<Brush> TitleBrush =
new
ObservableCollection<Brush>();
TitleBrush.Add(Brushes.Crimson);
HierarchyItem.TitleBrush.Add(TitleBrush);
}
dimensionRoot.SubDimensions.Add(DimensionItem);
}
treeCube.Items.Add(dimensionRoot);
0
Hi James,
I prepared a sample project implementing Miro's suggestion. Can you take a look at it and let me know if it works for you or if your scenario requires a different approach.
Regards,
Tina Stancheva
the Telerik team
I prepared a sample project implementing Miro's suggestion. Can you take a look at it and let me know if it works for you or if your scenario requires a different approach.
Regards,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
James
Top achievements
Rank 1
answered on 23 Aug 2010, 09:23 AM
Hi Tina,
Yes that project can be modified to suit my needs.
Thanks for the help
James
Yes that project can be modified to suit my needs.
Thanks for the help
James