Telerik Forums
UI for WPF Forum
1 answer
114 views
http://stackoverflow.com/questions/15950458/wpf-data-binding-of-a-ribbon-control

WPF 4.5  Ribbon is ok.


but, RadRibbonView is error (error.jpg)

How fix error.


# Full source

<Window x:Class="TelerikRibbon.MainWindow"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                Title="MainWindow" Height="350" Width="525" Name="wind">

    <Window.Resources>

        <DataTemplate x:Key="MyButtonTemplate">            
            <telerik:RadRibbonButton Text="{Binding Header}" Background="Beige" />
        </DataTemplate>
        
        <DataTemplate x:Key="MySplitButtonTemplate">
            <telerik:RadRibbonSplitButton Text="{Binding Header}" Background="Yellow" />
        </DataTemplate>
        
        <DataTemplate x:Key="buttonTempl">
            <ContentControl x:Name="cc" Content="{Binding}"  ContentTemplate="{DynamicResource MySplitButtonTemplate}" />
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Items.Count}" Value="0">
                    <Setter TargetName="cc" Property="ContentTemplate" Value="{DynamicResource MyButtonTemplate}"/>
                </DataTrigger>      
            </DataTemplate.Triggers>
        </DataTemplate>
        
        <Style TargetType="RibbonGroup" x:Key="groupStyle">
            <Setter Property="Header" Value="{Binding Header}"/>
            <Setter Property="ItemsSource" Value="{Binding Items}"/>
            <Setter Property="ItemTemplate" Value="{StaticResource buttonTempl}"/>
        </Style>
        <Style TargetType="RibbonTab" x:Key="tabStyle">
            <Setter Property="Header" Value="{Binding Header}"/>
            <Setter Property="ItemsSource" Value="{Binding Items}"/>
            <Setter Property="ItemContainerStyle" Value="{StaticResource groupStyle}"/>
        </Style>

        <Style TargetType="telerik:RadRibbonGroup" x:Key="groupStyleForRad">
            <Setter Property="Header" Value="{Binding Header}"/>
            <Setter Property="ItemsSource" Value="{Binding Items}"/>
            <Setter Property="ItemTemplate" Value="{StaticResource buttonTempl}"/>
        </Style>
        <Style TargetType="telerik:RadRibbonTab" x:Key="tabStyleForRad">
            <Setter Property="Header" Value="{Binding Header}"/>
            <Setter Property="ItemsSource" Value="{Binding Items}"/>
            <Setter Property="ItemContainerStyle" Value="{StaticResource groupStyleForRad}"/>
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Ribbon ItemContainerStyle="{StaticResource tabStyle}" ItemsSource="{Binding ElementName=wind, Path=child}"/>
        <!--<telerik:RadRibbonView Grid.Row="1" ItemContainerStyle="{StaticResource tabStyleForRad}" ItemsSource="{Binding ElementName=wind, Path=child}"/>-->
    </Grid>

</Window>

==================

/// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        public ObservableCollection<AppAction> child
        {
            get
            {
                ObservableCollection<AppAction> reVal = new ObservableCollection<AppAction>();
                reVal.Add(
                    new AppAction()
                    {
                        Header ="File",
                        Items = new ObservableCollection<AppAction>() { 
                new AppAction() { Header ="Font", Items = new ObservableCollection<AppAction>() { 
                    new AppAction() { Header ="Arial" }, 
                    new AppAction() { Header ="Segoe UI", Items = new ObservableCollection<AppAction> () {
                            new AppAction() { Header = "..." }
                        } }, 
                    new AppAction() { Header ="Tahoma" } } }, 
                new AppAction() { Header ="Other", Items = new ObservableCollection<AppAction>() { 
                    new AppAction() { Header ="Colse" } } } }
                    });

                reVal.Add(
                    new AppAction()
                    {
                        Header ="View",
                        Items = new ObservableCollection<AppAction>() { 
                new AppAction() { Header ="A", Items = new ObservableCollection<AppAction>() { 
                    new AppAction() { Header ="AButton" } } }, 
                new AppAction() { Header ="B", Items = new ObservableCollection<AppAction>() { 
                    new AppAction() { Header ="BButton" } } }, 
                new AppAction() { Header ="C", Items = new ObservableCollection<AppAction>() { 
                    new AppAction() { Header ="CButton" } } } }
                    });
                return reVal;
            }
        }
    }

    public class AppAction : INotifyPropertyChanged
    {
        public ObservableCollection<AppAction> Items { get; set; }

        string header;
        public string Header
        {
            get { return header; }
            set { header = value; OnPropertyChanged("Header"); }
        }

        public AppAction()
        {
            Items = new ObservableCollection<AppAction>();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
    }


Kiril Vandov
Telerik team
 answered on 07 Oct 2014
2 answers
203 views
Hi,

I have defined a custom tooltip for RadTreeView. Also I have used HierarchicalDataTemplate for my RadTreeView. Code is as shown below.

 <telerik:RadTreeView Margin="8" IsDragDropEnabled="True"  Name="CollExperimentTreeView"  SelectedItem="{Binding ActiveExp, Mode=TwoWay}"
     SelectionMode="Single" IsSingleExpandPath="False" IsLineEnabled="True"   VerticalAlignment="Stretch"
       temTemplate="{StaticResource TreeViewTemplate}"  ItemsSource ="{Binding TreeViewCollection,  Mode=TwoWay}" />

Custom tooltip and  HierarchicalDataTemplate  defined as below:

 <UserControl.Resources>
        <Style TargetType="{x:Type telerik:RadTreeViewItem}">
            <Setter Property="ToolTip" >
                <Setter.Value>
                    <ToolTip>
                        <ToolTip.Content>
                            <StackPanel Orientation="Vertical">
                                <StackPanel Orientation ="Horizontal">
                                    <TextBlock Text="Started:   " />
                                    <TextBlock Text="{Binding StartDate}" />
                                </StackPanel>
                                <StackPanel Orientation ="Horizontal">
                                    <TextBlock Text="Last Changed:   " />
                                    <TextBlock Text="{Binding LastAccess}" />
                                </StackPanel>
                                <TextBlock Text="{Binding Description}" />
                            </StackPanel>
                        </ToolTip.Content>
                    </ToolTip>
                </Setter.Value>
            </Setter>
        </Style>
        <HierarchicalDataTemplate x:Key="TreeViewTemplate" ItemsSource="{Binding Path=Experiments}">
            <TextBlock VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  Text="{Binding Name}" />              
        </HierarchicalDataTemplate>
    </UserControl.Resources>

I do not want to display tooltip for those nodes that shows TextBlock containing Name,( HierarchicalDataTemplate )  

Please help

Thanks
Divya
Top achievements
Rank 1
 answered on 07 Oct 2014
3 answers
204 views
I have using a radribbon view in my wpf application.I need to change the color of the active tab(1) and the tab pane(2).Please see the attached file.
here is my code


  
<Window
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="WpfApplication1.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="13*"/>
            <RowDefinition Height="19*"/>
        </Grid.RowDefinitions>
 
        <telerik:RadRibbonView  VerticalAlignment="Top" Background="#FF09587E" MinimizeButtonVisibility="Visible" BorderBrush="{DynamicResource {x:Static SystemColors.InfoTextBrushKey}}" Foreground="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" Grid.RowSpan="2">
            <telerik:RadRibbonTab Header="RibbonTab" Background="{DynamicResource {x:Static SystemColors.ActiveCaptionTextBrushKey}}"  OpacityMask="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
                <telerik:RadRibbonGroup Header="TEEEEE"/>
            </telerik:RadRibbonTab>
        </telerik:RadRibbonView>
 
    </Grid>
</Window>
Arun
Top achievements
Rank 1
 answered on 07 Oct 2014
1 answer
123 views
Hello, I'm working on a WPF application and using the RadChart control.
I'm familiar with the ItemToolTipFormat and DataPointMember="Tooltip" features, but I wonder if the following is possible:

I've attached an image for demonstration:
Is it possible that when I hover with the mouse cursor on the x axis categories, I'll get a tooltip:
For example: In the attached image, when I hover on the word May (or Sep or Nov and etc) with the mouse cursor, I will then get a tooltip.

What happens with the mentioned features above, I get a tooltip on the diagram itself, but as mentioned, I want a tooltip on the category itself on the x axis (when I hover on the months' words as displayed in the image).

Thank you in advance for your help!
 

Martin Ivanov
Telerik team
 answered on 06 Oct 2014
5 answers
1.1K+ views
Hi,

I'm creating a RadDocument from code and would like to be able to
determine the actual height of a specific tableRow.

I actually have two tables, and would like to have all the rows to have the same height ( = max of both tables):

for (int i = 0; i < rouwCount; i++)
{
    var maxHeight = tables.Max(x => x.Rows.ElementAt(i).Height);
    foreach (var table in tables)
    {
        table.Rows.ElementAt(i).Height = maxHeight;
    }
     
}

However, the height property is always zero. I understand this is not the actual height, is there a way to determine this?

Thanks,

Koen
Petya
Telerik team
 answered on 06 Oct 2014
2 answers
245 views
I have a RadGridView which is bound to an IQueryable. The initial data load is a bit slow, but is expected. However when I scroll at all it seems the data source is queried again. Thus performing any operations against the grid is fairly slow. I have solved this a bit by implementing the data pager. I have noticed that with a data page of 50 then scrolling to the bottom of the page yields a re-query. Then scrolling to the top does the same. However scrolling back to the bottom the data is cached. After this the single page can be scrolled very quickly.

Is it possible for the Grid to download 2 or 3 times more data than displayed, or the entire page size of content, so that it can act as a display buffer? Thus I can work with larger page sizes?
Dimitrina
Telerik team
 answered on 06 Oct 2014
1 answer
149 views
Hi,

I am trying to set different row heights on a row depending on a value in the underlying data.

So far I have worked out I can do the following...

var rows = rgv.ChildrenOfType<GridViewRow>();

int counter = 0;

foreach (GridViewRow gridViewRow in rows)
{
    gridViewRow.Height = 20.0 + counter;
    counter += 10;
}

This will set each row height to be 10 greater than its predecessor. The issue with this method is that the datagrid seems to calculate the height of the "rowspanel" based on the standard rowheight property and does not draw a vertical scroll bar, and also draws the horizontal scroll bar off the bottom of the visible area where it is not accessible.

My questions are is there a better way to achieve what I want? Maybe apply a style to the row whose height is bound to a property in the underlying data? Or is there some method I can call to "refresh" the datagrid to make it draw the horizontal scroll bar in the correct place and detect it needs to draw a vertical scroll bar.

Thanks

Andy


Dimitrina
Telerik team
 answered on 06 Oct 2014
9 answers
591 views
How would I programmatically add a text watermark to a Word document?

We are using C#, .NET 4.5 for a WPF desktop application on Windows 7.  Telerik UI for WPF version 2014.2.617.45 is used.

This needs to
1. Create a new word document
2. Add several pages of text, tables and images to the word document
3. Add a user entered watermark such as "For Internal Use Only" to each page at 44 point and angled from bottom left to top right.
4. The watermark should appear on all pages
5. Save the document in MS Word 2010 format if possible

It needs to be done in C# since there is no RichTextBox control in the application.


Petya
Telerik team
 answered on 06 Oct 2014
1 answer
191 views
Hello,

I ran into a snag recently that I realized was probably not a "common" request or feature set (due to most documentation/code examples).
The EditorAttribute  attribute class does its job for the compile-time defining of custom controls for properties. This part works well, however I was wondering if there is any other way to define custom controls of specific types for the RadPropertyGrid class at runtime?

Where was my "snag"?
Since The "target property" is passed to the constructor of the EditorAttribute when it is declared as an attribute above any given class's property/variable, any "target property" defined becomes a "static declaration" due to it being bound to a class's property's CustomProperty's constructor argument list within the assembly which ends up being a read-only list at run-time.

What scenario would require "run-time" defined EditorAttributes?
Since our scenario is a bit complex (run-time construction of classes), the easiest way to describe the issue would be that a "data container class" could have the same EditorAttribute defined for a generic property (as an example an Object class) of which could require the defined User Control Editor class to utilize different TargetProperty depending upon the type of the given example "Object class".

My temporary Fix (or potentially permanent with some instantiation reduction optimizations):
====================================================================
   public class CustomEditorAttribute : EditorAttribute
    {

        public CustomEditorAttribute(Type editorType)
            : base(editorType, GetTargetProperty(editorType), GetEditorStyle(editorType))
        {

        }

        public CustomEditorAttribute(Type editorType, EditorStyle editorStyle)
            : base(editorType, GetTargetProperty(editorType), GetEditorStyle(editorType))
        {

        }

        public CustomEditorAttribute(Type editorType, string targetProperty)
            : base(editorType, GetTargetProperty(editorType), GetEditorStyle(editorType))
        {
        }

        public CustomEditorAttribute(Type editorType, string targetProperty, EditorStyle editorStyle)
            : base(editorType, GetTargetProperty(editorType), GetEditorStyle(editorType))
        {

        }

        static CustomPropertyControl GetPropertyControl(Type type)
        {
            if (type.IsSubclassOf(typeof(CustomPropertyControl )))
            {
                return (CustomPropertyControl )InternalLib.AssemblyClassHelper.GetObjectInstance(type);
            }
            else
            {
                throw new Exception("The type (" + type.Name + ") is not a valid PropertyControl type!");
            }
        }

        public static String GetTargetProperty(Type type)
        {
            return GetPropertyControl(type).GetPropertyTargetName();
        }

        public static EditorStyle GetEditorStyle(Type type)
        {
            return GetPropertyControl(type).GetEditorStyle();
        }

    }
====================================================================
So, my current run-time assignment of EditorAttribute arguments "fix" was to derive from the EditorAttribute class and pass the results of statically defined methods within said class that invoke an instance of the Custom Editor Control class type defined within the EditorAttribute declaration in question.  The above code could also be modified further by passing a specific class type that is not the editor class in question, but a "type" container class which then could be modified at run-time based on different states of the application at the time of invocation.


Usage of the EditorAttribute Example:
====================================================================
...
        [InternalLib.PropertyControls.FieldProperties.CustomEditorAttribute(typeof(InternalLib.PropertyControls.ImagePropertyControl))]
        public Image ImageProperty
        {
            get
            {
                return imageProperty;
            }
            set
            {
                if (value != null && this.imageProperty != value)
                {
                    this.imageProperty = value;
                    this.OnPropertyChanged("ControlImage");
                    if (OnImageSourceChanged != null)
                    {
                        OnImageSourceChanged.Invoke(this.imageProperty.Source);
                    }
                }
            }
        }
...

Where:
public partial class ImagePropertyControl:CustomPropertyControl
{
...
        public override String GetPropertyTargetName()
        {
            return "SelectedItem";  //The control houses a RadListBox and as such the "SelectedItem" property of the listbox is the target property
        }

        public override EditorStyle GetEditorStyle()
        {
            return EditorStyle.Modal;
        } 

...
}

And where:
    public class BaseCustomPropertyControl:UserControl
    {
        
        public virtual String GetPropertyTargetName()
        {
            return String.Empty;
        }

        public virtual EditorStyle GetEditorStyle()
        {
            return EditorStyle.None;
        }
    }
====================================================================
However, it seems like a lot of work to simply be able to define the TargetPropery and the EditorStyle at run-time for a specific type.

Is there some way to (more easily) add EditorAttribute's programmatically to a RadPropertyGrid?

If not, then I figured I would post my current solution here in the event anyone else was trying to define class property EditorAttributes at run-time and needed one possible way to do it.

Cheers,

-Noel


p.s. 
~Side-Note on the included Code~
The code snippet included has an major optimization/instantiation issue.  One optimization one could do would be to create a
static dictionary in the BaseCustomPropertyControl class that is populated via a method always called in the BaseCustomPropertyControl
constructor that then in turn invokes the GetPropertyTargetName and GetEditorStyle methods (or is virtual and the child class is responsible
for returning proper information), stores both values into another container class/structure, and then adds the Key, as the Type, and
the Value, as the hypothetical container class, to the static dictionary which could then be checked via a static method defined within the
BaseCustomPropertyControl prior to constructing an entire new class instance each time.  This would reduce the number of
"bogus/ghost" instances of the child class derived from the BaseCustomPropertyControl (in this case it is the
ImagePropertyControl).  That would then reduce the number of times it would have to instantiate custom property controls (editors) when getting the TargetProperty and EditorStyle.
So, the example included in this post is strictly just a quick and dirty version.
Maya
Telerik team
 answered on 06 Oct 2014
12 answers
357 views
I am using the select all checkbox out of the box for selected items. I tried to change the header template using the following code:

<Style x:Key="MultiGridCheckbox" TargetType="telerik:GridViewCheckBoxColumn">
        <Setter Property="Header">
            <Setter.Value>
                <CheckBox IsChecked="{Binding Path=AllMembersAreChecked,                               
  RelativeSource={RelativeSource AncestorType=widgets:TelerikGrid}}"/>
            </Setter.Value>
        </Setter>
    </Style>

This works however the problem I'm having is if the user selects a row I want the header checkbox to be set to null to indicate to the user that there's a row(s) selected in the grid. Is that possible?
Vanya Pavlova
Telerik team
 answered on 06 Oct 2014
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?