Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
XamTreeGrid : displays hirearchical folder structure - how to change format of the folder
posted

Hi I have a XamTreeGrid, which displays the folder structure as follows

ALL 

|

---------- MEDTEST1

                |

                 _______ VALUE.BIN

                 --------------TEMP.BIN

Now , ALL can contain MEDTEST2, 3 etc... Based on a value like 1,2,3 which is  fetched from DB, i need to change the appearance of the folders 

for Example: if the value is 1, then Folder has to be UNDERLINED

if value = 2, then FOLDER name to be displayed in BOLD font

value = 3 , FOLDER in COLOR - blue ane BOLD font etc...

How can this be accomplished.

thanks,

Boomessh V

Parents
  • 2860
    Offline posted

    Hi Boomessh,

    Thank you for contacting Infragistics Developer Support!

    Sure, what you are looking for can be achieved by creating styles targeting the TreeCellValuePresenter and CellValuePresenter elements and assigning the relevant properties. Since the values would be conditional, they can be assigned with the help of a custom ValueConverter.

    The only special case would be the TextDecoration style, as it requires targeting the internal elements of the presenters. It can be handled through code, for example in the Loaded event handler, assigned through an EventSetter.

    All this is demonstrated in the sample I am attaching to this message. Please, check it out and let me know if it helps. Below are the relevant code snippets:

     

     <igWPF:XamTreeGrid.Resources>
         <Style TargetType="{x:Type igWPF:CellValuePresenter}">
             <Setter Property="Foreground"
                     Value="{Binding DataItem.Name, Converter={StaticResource fontConverter}}" />
             <Setter Property="FontStyle"
                     Value="{Binding DataItem.Name, Converter={StaticResource fontConverter}}" />
             <Setter Property="FontWeight"
                     Value="{Binding DataItem.Name, Converter={StaticResource fontConverter}}" />
             <EventSetter Event="Loaded"
                          Handler="CellValuePresenter_Loaded"></EventSetter>
         </Style>
         <Style TargetType="{x:Type igWPF:TreeCellValuePresenter}">
             <Setter Property="Foreground"
                     Value="{Binding DataItem.Name, Converter={StaticResource fontConverter}}" />
             <Setter Property="FontStyle"
                     Value="{Binding DataItem.Name, Converter={StaticResource fontConverter}}" />
             <Setter Property="FontWeight"
                     Value="{Binding DataItem.Name, Converter={StaticResource fontConverter}}" />
             <EventSetter Event="Loaded"
                          Handler="CellValuePresenter_Loaded"></EventSetter>
         </Style>

     public class FontConverter : IValueConverter
     {
         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
         {
             var text = value as string;
             if (text == null)
                 return DependencyProperty.UnsetValue;
    
             var lower = text.ToLowerInvariant();
    
             if (targetType == typeof(FontWeight))
             {
                 return lower.Contains("a") ? FontWeights.Bold : FontWeights.Normal;
             }
             if (targetType == typeof(FontStyle))
             {
                 return lower.Contains("b") ? FontStyles.Italic : FontStyles.Normal;
             }
            
             if (typeof(Brush).IsAssignableFrom(targetType))
             {
                 if (lower.Contains("a")) return Brushes.Red;
                 if (lower.Contains("b")) return Brushes.Green;
                 if (lower.Contains("c")) return Brushes.Blue;
                 return SystemColors.ControlTextBrush;
             }
    
             return DependencyProperty.UnsetValue;
         }
    
         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
         {
             return Binding.DoNothing;
         }
     }

            private void CellValuePresenter_Loaded(object sender, RoutedEventArgs e)
            {
                SimpleTextBlock underlinedText = Utilities.GetDescendantFromType((sender as DependencyObject), typeof(SimpleTextBlock), false) as SimpleTextBlock;
                if (underlinedText.Text.Contains("c"))
                    underlinedText.Style = this.FindResource("textDecorSimpleTxb") as Style;
            }

    Best regards,
    Bozhidara Pachilova
    Software Developer

    8875.XTGConditionalStyles.zip

Reply Children
No Data