This is a migrated thread and some comments may be shown as answers.

How to change style of ToolTip according to variable in code

4 Answers 255 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 10 Jan 2011, 01:55 PM

My code:

MainWindow.xaml

<Window x:Class="TestStyle.MainWindow"
        xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <telerik:RadButton Width="150" Content="Add new row" 
                    Command="telerikGrid:RadGridViewCommands.BeginInsert" 
                    CommandTarget="{Binding ElementName=RadGridView1}"  />
    </StackPanel>
    <telerikGrid:RadGridView 
                     SelectionMode="Single" 
                     AddingNewDataItem="RadGridView1_AddingNewDataItem"
                     x:Name="RadGridView1"  
                     AutoGenerateColumns="False">
            <telerikGrid:RadGridView.Columns>
                <telerikGrid:GridViewComboBoxColumn Header="Screen"  
                                        UniqueName="Screen"  
                                        x:Name="screen" 
                                        DataMemberBinding="{Binding IdGrid}" 
                                        DisplayMemberPath="Name" 
                                        SelectedValueMemberPath="IdListBox" >
                <telerikGrid:GridViewComboBoxColumn.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Name}" x:Name="textblockTooltip" Width="Auto" Padding="1,1,1,1"
                            <TextBlock.ToolTip
                            <ToolTip>   
                                    <ToolTip.Template
                                    <ControlTemplate TargetType="ToolTip"
                                      <Border CornerRadius="2,2,2,2" Width="100" Height="75" x:Name="borderTooltip" Background="Green" BorderBrush="#FF000000" Margin="2"
                                       <ContentPresenter Content="{Binding GridView}" Margin="2" /> 
                                      </Border
                                    </ControlTemplate
                                    </ToolTip.Template>  
                            </ToolTip
                            </TextBlock.ToolTip>
                            </TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </telerikGrid:GridViewComboBoxColumn.ItemTemplate>
            </telerikGrid:GridViewComboBoxColumn>
        </telerikGrid:RadGridView.Columns>
    </telerikGrid:RadGridView>
    </StackPanel>
</Window>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
  
namespace TestStyle
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
  
        bool resolution = false;
  
        public bool Resolution
        {
            get { return resolution; }
            set { resolution = value; }
        }
  
        public MainWindow()
        {
            InitializeComponent();
  
            ICommand beginInsertCommand = RadGridViewCommands.BeginInsert;
  
            ObservableCollection<ItemGrid> collectionGrid = new ObservableCollection<ItemGrid>();
            RadGridView1.ItemsSource = collectionGrid;
  
            ObservableCollection<ItemListBox> collectionListBox = new ObservableCollection<ItemListBox>();
             
            Label l1 = new Label();
            l1.Content = "Label 1";
            Label l2 = new Label();
            l2.Content = "Label 2";
            Grid gr1 = new Grid();
            gr1.Children.Add(l1);
            Grid gr2 = new Grid();
            gr2.Children.Add(l2);
  
            collectionListBox.Add(new ItemListBox(1, "Name 1", gr1));
            collectionListBox.Add(new ItemListBox(2, "Name 2", gr2));
            screen.ItemsSource = collectionListBox;
        }
  
        private void RadGridView1_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            e.NewObject = new ItemGrid(0);
        }
    }
}

ItemGrid.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel;
  
namespace TestStyle
{
    class ItemGrid : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
  
        private int idGrid;
  
        public int IdGrid
        {
            get { return idGrid; }
            set { idGrid = value; NotifyPropertyChanged("IdGrid"); }
        }
  
        public ItemGrid(int id)
        {
            this.idGrid = id;
        }
  
        private void NotifyPropertyChanged(string info)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
}

ItemListBox.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.ComponentModel;
  
namespace TestStyle 
{
    class ItemListBox : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
  
        int idListBox;
  
        public int IdListBox
        {
            get { return idListBox; }
            set { idListBox = value; NotifyPropertyChanged("IdListBox"); }
        }
  
        string name;
  
        public string Name
        {
            get { return name; }
            set { name = value; NotifyPropertyChanged("Name"); }
        }
  
        Grid gridView;
  
        public Grid GridView
        {
            get { return gridView; }
            set { gridView = value; NotifyPropertyChanged("GridView"); }
        }
  
        public ItemListBox(int idListBox, string name, Grid gridView)
        {
            this.idListBox = idListBox;
            this.gridView = gridView;
            this.name = name;
        }
  
        private void NotifyPropertyChanged(string info)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
}

I need to change Height property at Border "borderTooltip" according to value of property Resolution in ManWindow.xaml.cs.

I tried in constructor MainWindow() this:

if (Resolution == true)
    borderTooltip.Height = 75;
else 
    borderTooltip.Height = 50;

But i can´t access borderTooltip in code.Does somebody know please how to change borderTooltip.Height according to value of Resolution property?

4 Answers, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 10 Jan 2011, 02:54 PM
Hello Pavel,

 
Why not use ToolTipTemplateSelector as it is shown in the following online demo?
Also you need to ensure that this Resolution property is a property of your custom object and based on its value just return the desired tooltip.
Please let me know if you need any further assistance.
 

All the best,
Vanya Pavlova
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Pavel
Top achievements
Rank 1
answered on 10 Jan 2011, 05:23 PM

Thanks for response. I tried to use ToolTipTemplateSelector, but that is not working at all. I don´t need that ToolTip for GridViewComboBoxColumn, but I need that ToolTip for items in GridViewComboBox. I uploaded source codes of that application if you would like to look at it. 

EDIT:// Can´t attach zip file, so I uploaded it here

0
Accepted
Vanya Pavlova
Telerik team
answered on 13 Jan 2011, 04:29 PM
Hi Pavel,

You can pass the property through the data context - meaning you have to create properties on the items that are provided for ItemsSource and synchronize them OR you can create a dependency property on the window and bind to it using 'FindAncestor' binding like I did in the attached project. I hope it solves your problem.

In general the data within the popup should be responsible for stretching the tooltip so I can not imagine a good reason to pass such data that will justify a layout behavior.

Regards,
Vanya Pavlova
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Pavel
Top achievements
Rank 1
answered on 14 Jan 2011, 08:03 PM
That´s great. Thank you very much for yur help.
Tags
GridView
Asked by
Pavel
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Pavel
Top achievements
Rank 1
Share this question
or