Telerik Forums
UI for WPF Forum
5 answers
1.3K+ views
I'm relatively new to WPF and currently evaluating Telerik components. I got stuck when trying to bind RadTabControl items to content control objects. Probably the automatically generated RadTabItem doesn't like to wrap a content control (e.g. HeaderedContentControl) because regular objects work as expected. Am I trying to accomplish something that can't be done? Below you'll find a example that illustrates what I mean. Any help will be appreciated very much.

XAML:
<Window x:Class="RadControlsWpfApp1.MainWindow"
        xmlns:local="clr-namespace:RadControlsWpfApp1"
        xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
        Title="MainWindow" Height="350" Width="525">
      
    <Window.Resources>
        <DataTemplate x:Key="TabItemTemplate">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                <Image Width="18" Height="18" Source="{Binding Icon}" Stretch="Fill" Margin="0,0,3,0" />
                <TextBlock Text="{Binding Header, diagnostics:PresentationTraceSources.TraceLevel=High}"/>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>
  
    <Grid>
        <telerik:RadTabControl
            ItemsSource="{Binding Tabs}"
            ItemTemplate="{StaticResource TabItemTemplate}" />
    </Grid>
</Window>

Code behind:
using System.Windows;
  
namespace RadControlsWpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            DataContext = new MainWindowViewModel();
            InitializeComponent();
        }
    }
}

View model:
using System;
using System.Collections.ObjectModel;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Telerik.Windows.Controls.QuickStart;
  
namespace RadControlsWpfApp1
{
    public class MainWindowViewModel
    {
        private BitmapImage Bullet = new BitmapImage(new Uri("/RadControlsWpfApp1;component/bullet_red.png", UriKind.Relative));
  
        public ObservableCollection<IItem> Tabs { get; set; }
  
        public MainWindowViewModel()
        {
            Tabs = new ObservableCollection<IItem>();
            Tabs.Add(new ItemControl { Header = "Item 1", Icon = Bullet });
            Tabs.Add(new Item { Header = "Item 2", Icon = Bullet });
        }
    }
  
    public interface IItem
    {
        object Header { get; set; }
        ImageSource Icon { get; set; }
    }
  
    public class Item : IItem
    {
        public object Header { get; set; }
        public ImageSource Icon { get; set; }
    }
  
    public class ItemControl : HeaderedContentControl, IItem
    {
        public ImageSource Icon { get; set; }
    }
}
Tina Stancheva
Telerik team
 answered on 13 Jun 2011
9 answers
125 views
Hi there,

i'm having a strange issue with my gridview control in that when i set autogeneratecolumns to true and bind to a dataset, i am able to input values into cells and exit edit mode with the values still present in the cells but not so if i generate these columns programmatically.

i had to switch to programmatic cell loading because we need to load a dynamic list of columns to the grid based on user selections and so certain columns would only be added under certain conditions. however when i add a column to the grid, any input that i make in the cell just gets lost as soon as i exit edit mode.

this is how i create and add the gridviewdatacolumn:

GridViewDataColumn min = new GridViewDataColumn();
            min.UniqueName = "minCol";
            min.Header = "Min";
            min.FooterTextAlignment = TextAlignment.Right;
            min.TextAlignment = TextAlignment.Right;
            min.DataMemberBinding = new Binding("Min");
            min.DataType = Type.GetType("System.Int32");
            min.AggregateFunctions.Add(new SumFunction { SourceField = "Min"});
            radStoreGrid.Columns.Add(min);

what am i doing wrong? i've been sitting with this for over an hour and i just don't see the difference between this and the xaml declaration which worked fine...

thanks,
Nemanja
Maya
Telerik team
 answered on 13 Jun 2011
9 answers
154 views
hi
i need return all item rad tree view in hierarchical mode?
Davood
Top achievements
Rank 1
 answered on 12 Jun 2011
2 answers
78 views
Hi,
I use RadGridView in Grid panel:
<Grid.RowDefinitions>
    <RowDefinition Height="60"/>
    <RowDefinition Height="500"/>
</Grid.RowDefinitions>
The first row is Header and the second one RadGridView.
It works fine according to performance.


<Grid.RowDefinitions>
    <RowDefinition Height="60"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
On the other hand this RadGridView works fine according to flexibility but not UI performance.


How to achieve such effect like having RadGridView fast UI and on the other hand when user change size of the window,
RadGridView also adjust visible amount of rows to fulfill window size.
Thanks in advance.
Robert
Robert
Top achievements
Rank 1
 answered on 11 Jun 2011
0 answers
146 views
Hi,

I get two crashes when adding a new appointment in a RadScheduleView.
The type of the appointments is a custom BFAppointment class that I made which inherits from AppointmentBase.
The type of the AppointmentsSource of the control is a BFAppointmentList class I made, and this one inherits from ObservableCollection<BFAppointment>, so this shouldn't be an INotifyCollectionChanged bug.

The two crashes are:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.ArrayList.get_Item(Int32 index)
   at System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32 adjustedOldIndex, Int32 adjustedNewIndex)
   at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
   at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)
   at System.Collections.ObjectModel.Collection`1.RemoveAt(Int32 index)
   at System.Windows.Data.ListCollectionView.CancelNew()
   at Telerik.Windows.Controls.ScheduleView.ScheduleViewDataConnection.HackCollectionViewBug(Boolean isCommit) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleViewDataConnection.cs:line 875
   at Telerik.Windows.Controls.ScheduleViewBase.CommitNew(IAppointment appointment) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Editing.cs:line 341
   at Telerik.Windows.Controls.ScheduleViewBase.Commit() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Editing.cs:line 253
   at Telerik.Windows.Controls.ScheduleViewBase.OpenAppointmentDialog(Occurrence occurrence, AppointmentViewMode viewMode) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.EditingWithDialogs.cs:line 297
   at Telerik.Windows.Controls.ScheduleViewBase.CreateAppointmentWithDialog(Object parameter) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.EditingWithDialogs.cs:line 82
   at Telerik.Windows.Controls.ScheduleViewBase.OnCreateAppointmentExecuted(Object sender, ExecutedRoutedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Commands.cs:line 166
   at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
...


and:

System.ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime.
Parameter name: value
   at System.DateTime.AddTicks(Int64 value)
   at System.DateTime.Add(Double value, Int32 scale)
   at Telerik.Windows.Controls.DateTimeExtensions.SubtractInterval(DateTime dt, DateTimeInterval dateTimeInterval) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Extensions\DateTimeExtensions.cs:line 17
   at Telerik.Windows.Controls.ScheduleViewBase.GetFirstPartOfOccurrencesWithNoEndDates(DateSpan range, IEnumerable`1 source, Boolean moveForward, DateTimeInterval interval) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Common.cs:line 3571
   at Telerik.Windows.Controls.ScheduleViewBase.HasAppointmentsInRange(DateSpan range, Boolean skipIntersectedWithTheRangeAppointments, Boolean moveForward, DateTimeInterval interval) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Common.cs:line 1316
   at Telerik.Windows.Controls.ScheduleViewBase.OnQueryGoToPreviousAppointmentCanExecuted(Object sender, CanExecuteRoutedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Commands.cs:line 300
   at System.Windows.Input.CommandBinding.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)

...

I have some custom code when creating an appointment, as shown here:

void m_scheduleView_AppointmentCreating( object sender, AppointmentCreatingEventArgs e )
        {
            BFAppointment appointment = e.Appointment as BFAppointment;
            appointment.Schedule = ViewModel.BaseEntity;

            ScheduleTimespan timespan = new ScheduleTimespan();
            timespan.ScheduleId = ViewModel.BaseEntity.Id;

            appointment.TimespanViewModel = new ScheduleTimespanViewModel( timespan, ServiceLocator.Get<IEntityManager>() );
        }

        /// <summary>
        /// Handles the display of default Telerik dialogs to cancel them and substitute mine.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RadScheduleView_ShowDialog(object sender, ShowDialogEventArgs e)
        {
            // Dialog used to ask if we want to edit only the current occurrence or the whole series.
            // Since we ONLY support series, we skip the dialog.
            if ( e.DialogViewModel is RecurrenceChoiceDialogViewModel )
            {
                RecurrenceChoiceDialogViewModel vm = e.DialogViewModel as RecurrenceChoiceDialogViewModel;

                vm.IsSeriesModeSelected = true;
                e.DefaultDialogResult = true;
                e.Cancel = true;
            }
            // Replace the Telerik occurrence editor with our own.
            else if ( e.DialogViewModel is AppointmentDialogViewModel )
            {
                AppointmentDialogViewModel vm = e.DialogViewModel as AppointmentDialogViewModel;
                BFAppointment appointment = ( vm.Occurrence.Appointment as BFAppointment );

                if ( appointment.TimespanViewModel != null )
                {
                    // Show a window to edit the appointment.
                    ScheduleTimespanViewModel timespanVM = appointment.TimespanViewModel;

                    ScheduleTimespanControl control = new ScheduleTimespanControl() { ViewModel = timespanVM };
                    GenericEditableWindow window = new GenericEditableWindow( control, "ScheduleProperties", ServiceLocator.Get<IMainWindow>() as Window, GenericEditableWindowModeEnum.OK );
                    window.ShowDialog();
                }

                e.DefaultDialogResult = true;
                e.Cancel = true;
            }
        }

Setting e.Handled = true; in the AppointmentCreating event doesn't fix the issue.
Any pointers would be greatly appreciated.

Sebastien
Sébastien
Top achievements
Rank 1
 asked on 10 Jun 2011
4 answers
108 views
Hi.

I want to know, How can i achieve the func for disabling the certain rows in my grid which are not fulfill the criteria. For eg. I just want to enable only those rows whose shiptime is today. I' using the MVVM pattern.

Nikhil Jain
Top achievements
Rank 1
 answered on 10 Jun 2011
1 answer
67 views
Hi,

I was wondering if I can use the RadMap control to simulate the Interactive Directory Service in Malls and Buildings for the visitor to find their way. The direction locator, routing animation and such. Any suggestion for that, please? :)
Andrey
Telerik team
 answered on 10 Jun 2011
5 answers
145 views
GridView Not Loading in Word Addin TaskPane

We try to load Gridview in WPF XAML design time,but it is not loading.IF we try to load at runtime  by using c# code it works and added in Task Pane.


May i know how to fix the issue.


Thanks,
Anand
Anand
Top achievements
Rank 1
 answered on 10 Jun 2011
0 answers
75 views
I have Location list in a combobox .Need to call the method get employee by location and need to bind the name and id with the grid column on the combobox selection changed event....
Plz share code
swati
Top achievements
Rank 1
 asked on 10 Jun 2011
1 answer
469 views
Hi Telerik, All

I have GridView with GridViewSelectColumn and if i select couple of rows then apply filters then clear filters my all Selections is gone, means all previously selected rows become unselected.

is there anything i can do to retain same selection if i apply filter then clear filters

e.g
1. I have 5 rows 3 with Country US and 2 with Canada
2. Now i selected Canada rows
3. Apply filter on Country to US
4. only 3 rows visible "US"
5. Now clear filters
6. All 5 rows visible
7. All selected rows become unselected.


I want to keep that Canada rows selected.

I have used RadGriView in Winforms with filters and all my selections remmain selected even after filtering, so why WPF cant keep?


Kind Regards:
Maya
Telerik team
 answered on 10 Jun 2011
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?