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

Edittemplate selector in Outlookbar with Gridview

2 Answers 60 Views
OutlookBar
This is a migrated thread and some comments may be shown as answers.
Waut
Top achievements
Rank 1
Waut asked on 21 Jun 2013, 12:16 PM
Hello

I am trying something that I think the Outlookbar isn't created for, but I've no way else to do it (that I know of so please correct me if I'm wrong). Here is the story:
The view that i am creating has a gridview with grouping. The user can click on an item and edit its value. This can be a string, int, enum and so on. So i created a edittempateselctor that selected the right template. Everything worked, but then the costumer wanted something like the outlookbar to display the values. So I created that, but my problem is that my edittemplate isn't working anymore. The selected template is null. 
This is the working grid code:
<UserControl.Resources>
  <custom:EditTemplateSelector x:Key="EditTemplateSelector" />
</UserControl.Resources>
 
<telerik:RadGridView Grid.Row="2"
 ItemsSource="{Binding ListCollectionView, Mode=TwoWay}"
 SelectionMode="Single"
 AutoGenerateColumns="False"
 CanUserDeleteRows="False"
 CanUserFreezeColumns="False"
 CanUserReorderColumns="False"
 CanUserInsertRows="False"
 RowHeight="30"
 ColumnWidth="200"
 BorderThickness="0"
 ShowColumnHeaders="False"
 ShowGroupPanel="False"
 RowIndicatorVisibility="Collapsed"
  EditTriggers="CellClick">
 <telerik:RadGridView.Columns>
  <aucxis:GridViewDataColumn DataMemberBinding="{Binding SubID}" IsReadOnly="True"/>
  <aucxis:GridViewDataColumn DataMemberBinding="{Binding DataValue}"
   CellEditTemplateSelector="{DynamicResource EditTemplateSelector}"
   Width="Auto"/>
 </telerik:RadGridView.Columns>
</telerik:RadGridView>


this is the edittemplateselector.cs:
public class EditTemplateSelector : DataTemplateSelector
    {
        private IMessageBoxHandler _messageBoxHandler;
 
        public DataTemplate BoolDataTemplate { get; set; }
        public DataTemplate FloatDataTemplate { get; set; }
        public DataTemplate IntDataTemplate { get; set; }
        public DataTemplate StringTemplate { get; set; }
        public DataTemplate TimeSpanTemplate { get; set; }
        public DataTemplate EnumDataTemplate { get; set; }
        public DataTemplate FlagsEnumDataTemplate { get; set; }
        public DataTemplate InOutDoDataTemplate { get; set; }
 
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (_messageBoxHandler == null)
                _messageBoxHandler = DependencyInjection.Container.Resolve<IMessageBoxHandler>();
 
            var dataObject = (DataObject)item;
            if (dataObject == null)
            {
                const string nullValue = "This item has a nullvalue and can't be edited";
                if (_messageBoxHandler != null)
                    _messageBoxHandler.Show(nullValue, "Let op!", MessageBoxButton.OK, MessageBoxImage.Warning);
                else
                    MessageBox.Show(nullValue, "Let op!", MessageBoxButton.OK, MessageBoxImage.Warning);
                return base.SelectTemplate(null, container);
            }
            switch (dataObject.DataValue.GetType().ToString())
            {
                //standard Types
                case "System.Boolean":
                    return BoolDataTemplate;
                case "System.Single":
                    return FloatDataTemplate;
                case "System.Int32":
                    return IntDataTemplate;
                case "System.TimeSpan":
                    return TimeSpanTemplate;
                case "System.String":
                    return StringTemplate;
                //Enum types
                case "Aucxis.VAUC.Shared.Types.AlarmRequestTypes":
                case "Aucxis.VAUC.Shared.Types.Proxy.AutoHandProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.CO2InjectieStatesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.GasmetingStatesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.HighLowProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.InOutTypeProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.KoelStatesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.N2GeneratorKeuzeProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.N2GeneratorMethodesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.N2GeneratorStatesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.N2InjectieStatesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.O2InjectieStatesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.OntdooiTypesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteCO2InjectieStandProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteGasModusProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteKoelModusProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteKoelStandProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteN2InjectieStandProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteO2InjectieStandProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteStatussenProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.RuimteTypesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.VentStatesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.VentWinnerProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.VerdamperModussenProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.WachtrijCommandoProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.WachtrijItemTypesProxy":
                    return EnumDataTemplate;
                //flagEnums
                case "Aucxis.VAUC.Shared.Types.Proxy.AlarmTypesProxy":
                case "Aucxis.VAUC.Shared.Types.Proxy.LogTypesProxy":
                    return FlagsEnumDataTemplate;
                case "Aucxis.VAUC.Shared.Types.Proxy.InOutDOProxy":
                    return InOutDoDataTemplate;
                //Custom types (not yet implemented)*/
                default:
                    const string notYetImplemented = "This type is not yet implemented. Edit will result in fail";
                    if (_messageBoxHandler != null)
                        _messageBoxHandler.Show(notYetImplemented, "Let op!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    else
                        MessageBox.Show(notYetImplemented, "Let op!", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return base.SelectTemplate(item, container);
            }
        }
    }

The resourcedictionary with the templates:
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:custom="clr-namespace:Aucxis.VAUC.GUI.Client.Common.Custom;assembly=Aucxis.VAUC.GUI.Client.Common"
                    xmlns:aucxis="http://schemas.aucxis.com/1/wpf"
                    xmlns:converters="clr-namespace:Aucxis.VAUC.GUI.Client.Common.Converters;assembly=Aucxis.VAUC.GUI.Client.Common"
                    xmlns:controls="clr-namespace:Aucxis.iRAD.Controls;assembly=Aucxis.iRAD.Controls"
                    xmlns:touchScreenKeyBoard="clr-namespace:Aucxis.iRAD.Controls.Touch.Keyboard;assembly=Aucxis.iRAD.Controls.Touch"
                    xmlns:touch="clr-namespace:Aucxis.iRAD.Controls.Touch;assembly=Aucxis.iRAD.Controls.Touch"
                    xmlns:views="clr-namespace:Aucxis.VAUC.GUI.Client.Common.Custom.EditTemplates.Views;assembly=Aucxis.VAUC.GUI.Client.Common"
                    xmlns:controls2="clr-namespace:Aucxis.VAUC.GUI.Client.Common.Custom.Controls;assembly=Aucxis.VAUC.GUI.Client.Common">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Aucxis.Client.WPF;component/Themes/Generic.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Aucxis.iRAD.Controls.Touch;component/Themes/Generic.xaml" />
        <ResourceDictionary Source="pack://application:,,,/Aucxis.iRAD.Controls;component/Themes/Generic.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <aucxis:IntToDoubleConverter x:Key="IntToDoubleConverter" />
    <aucxis:InverseBooleanConverter x:Key="InverseBooleanConverter" />
    <converters:SingleToDoubleConverter x:Key="SingleToDoubleConverter" />
    <custom:EditTemplateSelector x:Key="EditTemplateSelector">
        <custom:EditTemplateSelector.BoolDataTemplate>
            <DataTemplate>
                <views:BoolView SelectedBool="{Binding DataValue, Mode=TwoWay}"
                               IsEnabled="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"
                               custom:FocusAttacher.Focus="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.BoolDataTemplate>
        <custom:EditTemplateSelector.IntDataTemplate>
            <DataTemplate>
                <controls:NumericUpDown x:Name="NumericUpDown" Value="{Binding DataValue, Mode=TwoWay, Converter={StaticResource IntToDoubleConverter}}"
                                        IsEnabled="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"
                                        touchScreenKeyBoard:TouchScreenNumericKeyboard.TouchScreenNumericKeyboard="True"
                                        NumberDecimalDigits="0"
                                        custom:FocusAttacher.Focus="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.IntDataTemplate>
        <custom:EditTemplateSelector.EnumDataTemplate>
            <DataTemplate>
                <views:EnumView Value="{Binding DataValue, UpdateSourceTrigger=PropertyChanged}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.EnumDataTemplate>
        <custom:EditTemplateSelector.FlagsEnumDataTemplate>
            <DataTemplate>
                <views:FlagsEnumView Value="{Binding DataValue, UpdateSourceTrigger=PropertyChanged}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.FlagsEnumDataTemplate>
        <custom:EditTemplateSelector.FloatDataTemplate>
            <DataTemplate>
                <controls:NumericUpDown x:Name="NumericUpDown" Value="{Binding DataValue, Mode=TwoWay, Converter={StaticResource SingleToDoubleConverter}}"
                                        IsEnabled="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"
                                        touchScreenKeyBoard:TouchScreenNumericKeyboard.TouchScreenNumericKeyboard="True"
                                        NumberDecimalDigits="2"
                                        custom:FocusAttacher.Focus="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.FloatDataTemplate>
        <custom:EditTemplateSelector.InOutDoDataTemplate>
            <DataTemplate>
                <views:InOutDOView DataContext="{Binding DataValue, UpdateSourceTrigger=PropertyChanged}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.InOutDoDataTemplate>
        <custom:EditTemplateSelector.StringTemplate>
            <DataTemplate>
                <touch:TextBox x:Name="txtBox" Text="{Binding DataValue, Mode=TwoWay}"
                               touchScreenKeyBoard:TouchScreenKeyboard.TouchScreenKeyboard="True"
                               IsEnabled="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"
                               SelectAllOnFocus="True"
                               custom:FocusAttacher.Focus="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.StringTemplate>
        <custom:EditTemplateSelector.TimeSpanTemplate>
            <DataTemplate>
                <controls2:TimeSpanPickerTouch x:Name="TimeSpan"
                                            Value="{Binding DataValue, Mode=TwoWay}"
                                            DaysVisible="False"
                                            HorizontalAlignment="Left"
                                            VerticalAlignment="Top"
                                            IsEnabled="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"
                                            custom:FocusAttacher.Focus="{Binding ReadOnly, Converter={StaticResource InverseBooleanConverter}}"/>
            </DataTemplate>
        </custom:EditTemplateSelector.TimeSpanTemplate>
    </custom:EditTemplateSelector>
</ResourceDictionary>


Not working code:
<controls:RadOutlookBar Grid.Row="2"
 ItemsSource="{Binding Groups}"
 IsMinimizable="False">
 <controls:RadOutlookBar.TitleTemplate>
  <DataTemplate>
   <Label Content="{Binding Header}"/>
  </DataTemplate>
 </controls:RadOutlookBar.TitleTemplate>
 <controls:RadOutlookBar.ItemTemplate>
  <DataTemplate>
    <Label Content="{Binding Header}"/>
  </DataTemplate>
 </controls:RadOutlookBar.ItemTemplate>
 <controls:RadOutlookBar.ContentTemplate>
  <DataTemplate>
   <telerik:RadGridView Grid.Row="2"
    ItemsSource="{Binding DataObjects, Mode=TwoWay}"
    SelectionMode="Single"
    AutoGenerateColumns="False"
    CanUserDeleteRows="False"
    CanUserFreezeColumns="False"
    CanUserReorderColumns="False"
    CanUserInsertRows="False"
    RowHeight="30"
    ColumnWidth="200"
    BorderThickness="0"
    ShowColumnHeaders="False"
    ShowGroupPanel="False"
    RowIndicatorVisibility="Collapsed"
    EditTriggers="CellClick">
    <telerik:RadGridView.Columns>
      <aucxis:GridViewDataColumn DataMemberBinding="{Binding SubID}" IsReadOnly="True"/>
      <aucxis:GridViewDataColumn DataMemberBinding="{Binding DataValue}"
       CellEditTemplateSelector="{StaticResource EditTemplateSelector}"
       Width="Auto"/>
    </telerik:RadGridView.Columns>
   </telerik:RadGridView>
  </DataTemplate>
 </controls:RadOutlookBar.ContentTemplate>
</controls:RadOutlookBar>

So when I use this last implementation the datatemplates in the Edittemplateselector returns null.
They are In the same project in the same view, I just don't get it :)

2 Answers, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 26 Jun 2013, 08:15 AM
Hello Waut,

Unfortunately the snippets that you provided are not compilable and I could not reproduce the behavior that you report on our side with our latest official release. This is why I created a sample project which uses the RadOutlookBar control. It has defined ContentTemplate, ItemTemplate and TitleTemplate properties. Furthermore, in the ContentTemplate of each RadOutlookBarItem there is a data-bound RadGridView control with some properties set and two columns with one CellEditTemplateSelector. The selector successfully switches between two DataTemplates.

Can you please take a look at the attached project and let me know if it works on your side. If you still can reproduce the issue please change the project so the issue can be reproduced and send it over. By doing so we will be able to further investigate the reasons behind this behavior.

Thank you for your cooperation.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Waut
Top achievements
Rank 1
answered on 03 Jul 2013, 08:47 AM
Your code does indeed work. And I found my problem:
I use multiple ResourceDictionaries. And those are linked in the appview. But in the window with the radbar is also referenced in the resources. When i removed this reference <custom:EditTemplateSelector x:Key="EditTemplateSelector" />  and kept the staticResource (because the resourcebundles are linked) it works fine.

So sorry to bother you with this stupid problem
Tags
OutlookBar
Asked by
Waut
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Waut
Top achievements
Rank 1
Share this question
or