Telerik Forums
UI for WPF Forum
4 answers
560 views
I have a RadTreeView bound to a collection that contains two types of objects, "Container" and "Item". I use an ItemTemplateSelector to set the correct (Hierarchical)DataTemplate. So far so good, but now I want to style the RadTreeViewItem so I can change selected visual styles and indents and such. I've added an ItemContainerStyle to the RadTreeView, but now the ItemTemplateSelector doesn't work anymore, the RadTreeView is rendered showing type names for all the items.

Is there a way to combine ItemTemplateSelector with an ItemContainerStyle? Should I be using another approach?

My sample code:
public class Container : INotifyPropertyChanged
{
   public Container()
   {
      Children = new ObservableCollection<object>();
   }
 
    
   // Public properties
 
   public ObservableCollection<object> Children { get; private set; }
 
   private string _displayName;
   public string DisplayName
   {
      get { return _displayName; }
      set
      {
         _displayName = value;
         OnPropertyChanged("DisplayName");
      }
   }
 
 
   // INotifyPropertyChanged members
 
   public event PropertyChangedEventHandler PropertyChanged;
   private void OnPropertyChanged(string propertyName)
   {
      if(PropertyChanged != null)
      {
         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
   }
}
 
public class Item : INotifyPropertyChanged
{
   // Public properties
 
   private string _displayName;
   public string DisplayName
   {
      get { return _displayName; }
      set
      {
         _displayName = value;
         OnPropertyChanged("DisplayName");
      }
   }
 
 
   // INotifyPropertyChanged members
 
   public event PropertyChangedEventHandler PropertyChanged;
   private void OnPropertyChanged(string propertyName)
   {
      if(PropertyChanged != null)
      {
         PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
   }
}
 
public partial class MainWindow
{
   // Constructors
 
   public MainWindow()
   {
      InitializeComponent();
      CreateDummyData();
      DataContext = this;
   }
 
 
   // Public properties
 
   public ObservableCollection<object> Items { get; private set; }
 
 
   // Private methdods
 
   private void CreateDummyData()
   {
      Items = new ObservableCollection<object>();
 
      // level 0
      var i1 = new Item { DisplayName = "Item 1" };
      Items.Add(i1);
 
      var i2 = new Item { DisplayName = "Item 2" };
      Items.Add(i2);
 
      var c1 = new Container { DisplayName = "Container 1" };
      Items.Add(c1);
 
      var c2 = new Container { DisplayName = "Container 2" };
      Items.Add(c2);
 
      var i8 = new Item { DisplayName = "Item 8" };
      Items.Add(i8);
 
      var c3 = new Container { DisplayName = "Container 3" };
      Items.Add(c3);
 
      var i11 = new Item { DisplayName = "Item 11" };
      Items.Add(i11);
 
 
      // Level 1.0
      var c1S1 = new Container { DisplayName = "Subcontainer 1" };
      c1.Children.Add(c1S1);
 
      var c1S2 = new Container { DisplayName = "Subcontainer 2" };
      c1.Children.Add(c1S2);
 
      var i3 = new Item { DisplayName = "Item 3" };
      c1.Children.Add(i3);
 
      var i4 = new Item { DisplayName = "Item 4" };
      c1.Children.Add(i4);
 
      var i12 = new Item { DisplayName = "Item 12" };
      c1.Children.Add(i12);
 
 
      // Level 1.0.0
      var c1S1S1 = new Container { DisplayName = "Subsubcontainer 1" };
      c1S1.Children.Add(c1S1S1);
 
      var i5 = new Item { DisplayName = "Item 5" };
      c1S1.Children.Add(i5);
 
      var i6 = new Item { DisplayName = "Item 6" };
      c1S1.Children.Add(i6);
 
      var i7 = new Item { DisplayName = "Item 7" };
      c1S1S1.Children.Add(i7);
 
 
      // Level 1.0.1
 
      var i15 = new Item { DisplayName = "Item 15" };
      c1S2.Children.Add(i15);
 
      var i16 = new Item { DisplayName = "Item 16" };
      c1S2.Children.Add(i16);
 
      var i17 = new Item { DisplayName = "Item 17" };
      c1S2.Children.Add(i17);
 
      // Level 1.0.0.0
 
      var i13 = new Item { DisplayName = "Item 13" };
      c1S1S1.Children.Add(i13);
 
      var i14 = new Item { DisplayName = "Item 14" };
      c1S1S1.Children.Add(i14);
 
 
      // Level 3.0
 
      var i9 = new Item { DisplayName = "Item 9" };
      c3.Children.Add(i9);
 
      var i10 = new Item { DisplayName = "Item 10" };
      c3.Children.Add(i10);
   }
}
 
public class MyDataTemplateSelector : DataTemplateSelector
{
   public HierarchicalDataTemplate ContainerTemplate { get; set; }
   public DataTemplate ItemTemplate { get; set; }
 
   public override DataTemplate SelectTemplate(object item, DependencyObject container)
   {
      if(item is Item)
      {
         return ItemTemplate;
      }
 
      return ContainerTemplate;
   }
}

<Window
   xmlns:TreeViewTest="clr-namespace:TreeViewTest"
   xmlns:System_Windows_Automation="clr-namespace:System.Windows.Automation;assembly=UIAutomationTypes"
   x:Class="TreeViewTest.MainWindow"
   Title="MainWindow" Height="350" Width="525">
   <Window.Resources>
 
      <HierarchicalDataTemplate x:Key="ContainerTemplate" ItemsSource="{Binding Children}">
         <TextBlock Text="{Binding DisplayName}" Background="Red"/>
      </HierarchicalDataTemplate>
 
      <DataTemplate x:Key="ItemTemplate">
         <TextBlock Text="{Binding DisplayName}" Background="Green"/>
      </DataTemplate>
 
      <TreeViewTest:MyDataTemplateSelector
         x:Key="MyDataTemplateSelector"
         ContainerTemplate="{StaticResource ContainerTemplate}"
         ItemTemplate="{StaticResource ItemTemplate}"/>
 
    <Style x:Key="RadTreeViewItemStyle" TargetType="{x:Type telerik:RadTreeViewItem}">
        <Setter Property="FocusVisualStyle">
            <Setter.Value>
                <Style>
                    <Setter Property="Control.Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle Margin="0" Stroke="Transparent" StrokeThickness="0"/>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <!--<Setter>
            <Setter.Value>
                <System_Windows_Automation:ToggleState>Off</System_Windows_Automation:ToggleState>
            </Setter.Value>
        </Setter>--> <!--causes exception-->
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Padding" Value="1,0,5,0"/>
        <Setter Property="IsDropAllowed" Value="True"/>
        <Setter Property="ItemsOptionListType" Value="Default"/>
        <Setter Property="IsEnabled" Value="True"/>
        <Setter Property="MinHeight" Value="24"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type telerik:RadTreeViewItem}">
                    <Grid x:Name="RootElement">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="EditStates">
                                <VisualState x:Name="Display"/>
                                <VisualState x:Name="Edit">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="EditHeaderElement">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Header">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Header"/>
                                        <DoubleAnimation Duration="0" To="0.35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Image"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.1" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="MouseOverVisual"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected"/>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="SelectionVisual">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="SelectedUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="SelectionUnfocusedVisual">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="LoadingOnDemandStates">
                                <VisualState x:Name="LoadingOnDemand">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="LoadingVisual">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Expander">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Collapsed</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Duration="0:0:1" From="0" RepeatBehavior="Forever" To="359" Storyboard.TargetProperty="Angle" Storyboard.TargetName="LoadingVisualAngleTransform"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="LoadingOnDemandReverse"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FocusVisual">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ExpandStates">
                                <VisualState x:Name="Expanded">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="ItemsHost">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Collapsed"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="HeaderRow" Background="Transparent" MinHeight="{TemplateBinding MinHeight}" SnapsToDevicePixels="True">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="2"/>
                            <Border x:Name="MouseOverVisual" BorderBrush="#FFFFC92B" BorderThickness="1" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="1" Opacity="0">
                                <Border BorderBrush="White" BorderThickness="1" CornerRadius="0">
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFFFFBA3" Offset="1"/>
                                            <GradientStop Color="#FFFFFBDA" Offset="0"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </Border>
                            <Border x:Name="SelectionUnfocusedVisual" BorderBrush="#FFDBDBDB" BorderThickness="1" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="1" Visibility="Collapsed">
                                <Border BorderBrush="Transparent" BorderThickness="1" CornerRadius="0">
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="0,1">
                                            <GradientStop Color="#FFF8F6F9" Offset="0"/>
                                            <GradientStop Color="#FFF0F0F0" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </Border>
                            <Border x:Name="SelectionVisual" BorderBrush="#FFFFC92B" BorderThickness="1" Grid.ColumnSpan="6" Grid.Column="2" CornerRadius="1" Visibility="Collapsed">
                                <Border BorderBrush="White" BorderThickness="1" CornerRadius="0">
                                    <Border.Background>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FFFCE79F" Offset="1"/>
                                            <GradientStop Color="#FFFDD3A8"/>
                                        </LinearGradientBrush>
                                    </Border.Background>
                                </Border>
                            </Border>
                            <StackPanel x:Name="IndentContainer" Orientation="Horizontal">
                                <Rectangle x:Name="IndentFirstVerticalLine" Stroke="#FFCCCCCC" Visibility="Collapsed" VerticalAlignment="Top" Width="1"/>
                            </StackPanel>
                            <Grid x:Name="ListRootContainer" Grid.Column="1" HorizontalAlignment="Center" MinWidth="20">
                                <Rectangle x:Name="HorizontalLine" HorizontalAlignment="Right" Height="1" Stroke="#FFCCCCCC" VerticalAlignment="Center"/>
                                <Rectangle x:Name="VerticalLine" HorizontalAlignment="Center" Stroke="#FFCCCCCC" VerticalAlignment="Top" Width="1"/>
                                <ToggleButton x:Name="Expander" Background="{TemplateBinding Background}" IsTabStop="False"/>
                                <Grid x:Name="LoadingVisual" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed" VerticalAlignment="Center">
                                    <Grid.RenderTransform>
                                        <TransformGroup>
                                            <RotateTransform Angle="0" CenterY="0.5" CenterX="0.5"/>
                                        </TransformGroup>
                                    </Grid.RenderTransform>
                                    <Path Data="M1,0A1,1,90,1,1,0,-1" Height="10" StrokeStartLineCap="Round" Stretch="Fill" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" Width="10"/>
                                    <Path Data="M0,-1.1L0.1,-1 0,-0.9" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Left" Height="4" Margin="5,-1.5,0,0" Stretch="Fill" StrokeThickness="1" VerticalAlignment="Top" Width="4"/>
                                </Grid>
                            </Grid>
                            <CheckBox x:Name="CheckBoxElement" Grid.Column="2" IsTabStop="False" Margin="5,0,0,0" Visibility="Collapsed" VerticalAlignment="Center">
                                <telerik:StyleManager.Theme>
                                    <telerik:Office_BlackTheme/>
                                </telerik:StyleManager.Theme>
                            </CheckBox>
                            <RadioButton x:Name="RadioButtonElement" Grid.Column="2" IsTabStop="False" Margin="5,0,0,0" Visibility="Collapsed" VerticalAlignment="Center">
                                <telerik:StyleManager.Theme>
                                    <telerik:Office_BlackTheme/>
                                </telerik:StyleManager.Theme>
                            </RadioButton>
                            <Image x:Name="Image" Grid.Column="3" HorizontalAlignment="Center" MaxWidth="16" MaxHeight="16" Margin="2" VerticalAlignment="Center"/>
                            <Rectangle x:Name="FocusVisual" Grid.ColumnSpan="6" Grid.Column="2" IsHitTestVisible="False" RadiusY="3" RadiusX="3" Stroke="Black" StrokeThickness="1" StrokeDashArray="1 2" Visibility="Collapsed"/>
                            <Grid Grid.ColumnSpan="2" Grid.Column="4">
                                <ContentPresenter x:Name="Header" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                <ContentPresenter x:Name="EditHeaderElement" ContentTemplate="{TemplateBinding HeaderEditTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" Visibility="Collapsed" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                            </Grid>
                        </Grid>
                        <ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Visibility="Collapsed"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <telerik:TreeViewPanel IsItemsHost="True" IsVisualCacheEnabled="False" VerticalAlignment="Bottom"/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>
 
   </Window.Resources>
   <Grid>
      <telerik:RadTreeView
         ItemsSource="{Binding Items}"
         ItemTemplateSelector="{StaticResource MyDataTemplateSelector}"
         ItemContainerStyle="{DynamicResource RadTreeViewItemStyle}"/>
   </Grid>
</Window>
Petar Mladenov
Telerik team
 answered on 08 Mar 2018
5 answers
162 views
I have got an issue when copying to excel from grid using custom Header. The grid has custom headers similar to below
<telerik:GridViewDataColumn x:Name="name1">
 <telerik:GridViewDataColumn.Header>
<Grid>
   <textBlock text = "header1"/>
...
</Grid>

When the data is pasted into excel it prints the name of the column as Grid ( to string invoked on the header).  I tried using CopyingCellClipboardContent event but that only fires for cell values and not for header copying.  I wanted to give my custom header names to be copied across to excel. How can i do that?

Thanks
Avneesh


Dilyan Traykov
Telerik team
 answered on 08 Mar 2018
3 answers
1.2K+ views

Hello,

Using components from UI for WPF R2 2017 ... It appears that RadGridView column virtualization is causing some binding errors, which in turn seem to place the GridView in a state where column header bindings fail when those columns are not rendered initially due to virtualization.  For example, the sample below works if EnableColumnVirtualization is set to false, or if the window size is large enough such that all columns are rendered (such as 800 in the example below).

With the Office2016 theme, I'm getting two types of binding errors:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Telerik.Windows.Controls.RadGridView', AncestorLevel='1''. BindingExpression:Path=DataContext.HeaderText; DataItem=null; target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Telerik.Windows.Controls.GridView.DataCellsPresenter', AncestorLevel='1''. BindingExpression:Path=Foreground; DataItem=null; target element is 'ContentControl' (Name='PART_ContentPresenter'); target property is 'Foreground' (type 'Brush')

(The sample has a single row in the ItemsSource ... real world situations would produce dozens+ of the errors looking for DataCellsPresenter.)

Other themes I've tested just produce the first binding error.

Here's the .xaml:

<Window x:Class="TelerikWpfApp.MainWindow"
    Title="MainWindow" Height="300" Width="400">
  <Grid>
    <telerik:RadGridView EnableColumnVirtualization="True"
        AutoGenerateColumns="False"
        GroupRenderMode="Flat"
        ItemsSource="{Binding TestObjects}">
      <telerik:RadGridView.Columns>
          <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"/>
          <telerik:GridViewDataColumn Header="Column 1 Name" DataMemberBinding="{Binding Column1}"/>
          <telerik:GridViewDataColumn Header="Column 2 Name" DataMemberBinding="{Binding Column1}"/>
          <telerik:GridViewDataColumn Header="Column 3 Name" DataMemberBinding="{Binding Column1}"/>
          <telerik:GridViewDataColumn Header="Column 4 Name" DataMemberBinding="{Binding Column1}"/>
          <telerik:GridViewDataColumn Header="Column 5 Name" DataMemberBinding="{Binding Column1}"/>
          <telerik:GridViewDataColumn Header="Column 6 Name" DataMemberBinding="{Binding Column1}"/>
                 
          <telerik:GridViewDataColumn DataMemberBinding="{Binding Column1}">
            <telerik:GridViewDataColumn.Header>
              <TextBlock Text="{Binding DataContext.HeaderText, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}"/>
            </telerik:GridViewDataColumn.Header>
          </telerik:GridViewDataColumn>
      </telerik:RadGridView.Columns>
    </telerik:RadGridView>
  </Grid>
</Window>

 

And here's the code:

using System.Collections.Generic;
using System.Windows;
using Telerik.Windows.Controls;
 
namespace TelerikWpfApp
{
     public partial class MainWindow : Window
    {
        public class TestObject
        {
            public string Name { get; set; }
            public string Column1 { get; set; }
        }
 
        public MainWindow()
        {
            StyleManager.ApplicationTheme = new Office2016Theme();
 
            InitializeComponent();
 
            this.DataContext = this;
 
            TestObjects = new List<TestObject>
            {
                new TestObject { Name = "1", Column1 = "Column1" }
            };
        }
 
        public List<TestObject> TestObjects { get; set; }
 
        public string HeaderText { get { return "Test"; } }
    }
}

 

Any assistance would be appreciated.

Dilyan Traykov
Telerik team
 answered on 08 Mar 2018
1 answer
111 views

There is some display error in the png,but someother UI display right Chinese.

What would be the cause?

Thanks。

Martin Ivanov
Telerik team
 answered on 08 Mar 2018
1 answer
113 views
Hi, RichTextBox is not the list of supported controls for CodedUI, can we expect the support in future, if yes? What could be the
Tanya
Telerik team
 answered on 08 Mar 2018
1 answer
152 views

Hello!

I accidentally click the release button so that "https://www.telerik.com/forums/ribbonwindow-no-transparent", I want to help delete it.

 

I use the Material theme in my RibbonWindow.

When I Producing my program.The window has a White border.

I compare it to demo,It seems to be a shadow, but it's no transparent.

I tried to modify the transparency of the window. The window was not transparent, and all the colors were white.

I think the problem is that transparency is replaced by white, what should I do to correct this problem

 

Martin Ivanov
Telerik team
 answered on 07 Mar 2018
1 answer
143 views

When the PDFViewer is using FixedDocumentPagesPresenter it tends to change position (it jumps to different pages) when a page is rotated and the same thing can also occur when zooming in/out.

To see this, simply open any PDF with more than a few pages - the one I'm currently testing with has 18 pages, move away from the first few pages (e.g. go to page 12), and rotate the page. The position jumps several pages and is restored if you rotate 360 degs.  In my test doc, it jumps to page 16 when rotated 90 / 270 degrees and back to page 12 when rotated 0 / 180 degrees.

There's a similar problem when zooming in, but I think you need a document with a few hundred pages to see this.

It all seems to be fine when using FixedDocumentSinglePageViewPresenter.

Any chance you can fix this?

Thanks.

Deyan
Telerik team
 answered on 07 Mar 2018
3 answers
832 views
I would like to determine how many distinct values are shown in a grid column after filtering is applied.

The filter parameter (true) in grid.GetDistinctValues(column, true, null) considers the other columns (but not the specified column).  So this method returns every distinct value for the considered column and is not restricted to just those distinct values that are actually shown in the column as a result of the filtering currently applied to that column as well as to the other columns.

So this method doesn't suit my purpose.

I would like to know the number of distinct values actually shown in a column to support the following two scenarios.  (1) If there are zero distinct values displayed in a column, then the last filtering operation over-constrained the result set and can be undone (with user notification).  (2) If there is only one distinct value, then the column can be hidden and the column-header/single-unique-value pair can be transferred to a "common values" grid.

This approach works well with our datasets.  As the user applies filtering operations, an 8000 row, 65 column datasource typically gets reduced to about 20 rows and 5 to 10 columns each containing more than one distinct value.  All other single-valued columns are displayed in an adjacent common-values grid.

In the grid.FilterDescriptors.CollectionChanged event, I invoke the method which consolidates the common-values.  For this method, I need to know if there is only one distinct value.

Many thanks!
jamsheer
Top achievements
Rank 1
Veteran
 answered on 07 Mar 2018
0 answers
160 views
I Have a WindowsService project.In this service when I render any UserControl, the png file is empty.

for test i write the following code to export a TextBlock but result is an empty png file.

protected override void OnCustomCommand(int command)
{
    Export();

    base.OnCustomCommand(command);
}

private void Export()
{
    var thread = new Thread(() =>
    {

        var grid = new Grid();
        grid.Children.Add(new TextBlock() { Text = "ExportTest", FontSize = 60, Background = Brushes.Red, Foreground = Brushes.Blue });
        double widthg = grid.Width > 0 ? grid.Width : 1024;
        double heightg = grid.Height > 0 ? grid.Height : 768;
        grid.Measure(Size.Empty);
        grid.Measure(new Size(widthg, heightg));
        grid.Arrange(new Rect(0, 0, widthg, heightg));
        grid.UpdateLayout();

        var bitmap = new PngBitmapEncoder();
        ExportExtensions.ExportToImage(grid, @"..\ExportTest.png", bitmap);
    });

    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
    thread.Join();
}

Note: when I run the export function in wpf project, it works perfect.

there is my project:
http://www.mediafire.com/file/aij5sg4zx80yc73/ExportProject.rar
any body can help me?
Ahmad
Top achievements
Rank 1
 asked on 06 Mar 2018
2 answers
95 views

It seems like there's a limitation to Cluster locations and a bug regarding its Bounds. I noticed that the location of a Cluster is always at the location of the first item added to it. I would expect that it actually would be at the center of all added items. Looking at the ClusterData.Add method it seems like it would be easy to update the Cluster-location there since the bounds are updated each time a new item is added. I tried solving it by overriding the DefaultClusterGenerator like the code below, but then I noticed that the calculation for the Bounds are actually wrong in the ClusterData.Add method. The last Math.Min should be a Math.Max. In the end I had to calculate the Bounds myself, and then update the Cluster Location.

 

public class ClusterGenerator : DefaultClusterGenerator
 
{
    public override ClusterData CreateCluster(Location center, object item)
    {
        var clusterData = base.CreateCluster(center, item);
        clusterData.AutoCalculateBounds = true;
 
        clusterData.PropertyChanged += this.ClusterDataOnPropertyChanged;
        return clusterData;
    }
    private void ClusterDataOnPropertyChanged(object sender, PropertyChangedEventArgs args)
    {
        // Check if an item has been added or removed
        if (args.PropertyName == nameof(ClusterData.Count))
        {
            var clusterData = sender as ClusterData;
            if (!clusterData.Bounds.IsEmpty)
            {
                clusterData.Location = clusterData.Bounds.Center;
            }
        }
    }
}
Petar Mladenov
Telerik team
 answered on 06 Mar 2018
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Expander
Slider
TileList
DataPager
PersistenceFramework
Styling
TimeBar
OutlookBar
TransitionControl
FileDialogs
Book
ToolBar
ColorPicker
TimePicker
MultiColumnComboBox
SyntaxEditor
VirtualGrid
NavigationView (Hamburger Menu)
Wizard
ExpressionEditor
WatermarkTextBox
DesktopAlert
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
LayoutControl
ProgressBar
Sparkline
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
Licensing
WebCam
CardView
DataBar
FilePathPicker
Callout
PasswordBox
SplashScreen
Localization
Rating
Accessibility
CollectionNavigator
AutoSuggestBox
Security
VirtualKeyboard
HighlightTextBlock
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Top users last month
Miljana
Top achievements
Rank 2
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Bronze
Cynthia
Top achievements
Rank 1
John
Top achievements
Rank 1
Iron
Mozart
Top achievements
Rank 1
Iron
Veteran
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?