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

Get Style Height property value

1 Answer 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fabiana
Top achievements
Rank 1
Fabiana asked on 12 Jul 2010, 06:57 PM
Hello support!

I created a new GridViewHeaderRow Style and use it in RadGridView. How to get , in page code, Height property of the the "CustomRadGridViewHeaderRow" style ? I need to know after Page_Loaded(), the GridViewHeaderRow Height .
Thanks!


 

 

 

<Style x:Key="CustomRadGridViewHeaderRow" TargetType="telerik:GridViewHeaderRow">

 

 

 

 

<Setter Property="Foreground" Value="Black" />

 

 

 

 

<Setter Property="FontSize" Value="11"></Setter>

 

 

 

 

<Setter Property="FontFamily" Value="Portable User Interface"></Setter>

 

 

 

 

<Setter Property="Background" Value="#E9D1D1D1" />

 

 

 

 

<Setter Property="BorderBrush" Value="White" />

 

 

 

 

<Setter Property="Height" Value="22" />

 

 

 

 

<Setter Property="MinHeight" Value="22" />

 

 

 

 

</Style>


 

 

 

 

<!--RadGridView-->

 

 

 

 

 

 

 

 

<telerik:RadGridView HeaderRowStyle="{StaticResource CustomRadGridViewHeaderRow}" x:Name="RadgrdInbox">

 

 

 

 

 

 

 

 

    <telerik:RadGridView.Columns>

 

 

 

 

 

 

 

 

        <telerik:GridViewDataColumn x:Name="RadColumnInboxFrom" Width = "*" IsReadOnly="True" Header="From" CellTemplate="{StaticResource FromTemplate}"/>

 

 

 

 

 

    </telerik:RadGridView.Columns>

 

 

 

 

 

 

 

 

</telerik:RadGridView>

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 13 Jul 2010, 11:26 AM
Hi Fabiana,

Imagine that you have defined a Style in your page like this:

<UserControl x:Class="DataControlsTestApplication_SL.MainPage"
    xmlns:ms="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:sw="clr-namespace:System.Windows;assembly=System.Windows.Controls"
    xmlns:local="clr-namespace:DataControlsTestApplication_SL;assembly=DataControlsTestApplication_SL"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
 
    <UserControl.Resources>
        <Style x:Key="MyStyle" TargetType="Button">
            <Setter Property="Height" Value="55"/>
        </Style>
    </UserControl.Resources>
 
    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Name="withRadGridView" Content="With RadGridView" Click="withRadGridView_Click"/>
            <Button Name="unboundMode" Content="Unbound Mode" Click="unboundMode_Click"/>
            <Button Name="dds" Content="With DomainDataSource" Click="dds_Click"/>
        </StackPanel>
        <sdk:Frame x:Name="ContentFrame" Grid.Row="1"/>
    </Grid>
</UserControl>

Then, if you write the following code in the code-behind of the page after the call to the InitializeComponent method, you will be able to get the height that you defined in XAML:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.Data.DataFilter;
using Telerik.Windows.Data;
using System.Diagnostics;
using System.Collections;
using Telerik.Windows.Controls;
using Telerik.SilverlightExtensions;
using System.ComponentModel.DataAnnotations;
 
namespace DataControlsTestApplication_SL
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
 
 
            if (this.Resources.Contains("MyStyle"))
            {
                Style myStyle = this.Resources["MyStyle"] as Style;
                if (myStyle != null)
                {
                    Setter heightSetter = myStyle.Setters.OfType<Setter>()
                        .Where(setter => setter.Property == Button.HeightProperty)
                        .FirstOrDefault();
                     
                    if (heightSetter != null)
                    {
                        var height = heightSetter.Value;
                        Debug.WriteLine(height);
                    }
                }
            }
        }
 
        private void withRadGridView_Click(object sender, RoutedEventArgs e)
        {
            this.ContentFrame.Source = new Uri("/WithRadGridView.xaml", UriKind.Relative);
        }
 
        private void unboundMode_Click(object sender, RoutedEventArgs e)
        {
            this.ContentFrame.Source = new Uri("/UnboundPage.xaml", UriKind.Relative);
        }
 
        private void dds_Click(object sender, RoutedEventArgs e)
        {
            this.ContentFrame.Source = new Uri("/WithDDSPage.xaml", UriKind.Relative);
        }
    }
}

The parts of the important code are in yellow. I hope this helps.

Kind regards,
Ross
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
Tags
GridView
Asked by
Fabiana
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or