Print Page | Close Window

Cocktail and Telerik Radwindows

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3892
Printed Date: 06-Jul-2020 at 11:35am


Topic: Cocktail and Telerik Radwindows
Posted By: decoda
Subject: Cocktail and Telerik Radwindows
Date Posted: 15-Jan-2013 at 2:34am
Hi
Another noob question , is their no sample on how Radwindow, Alert, Confirm, Prompt of telerik work in cocktail, or do i need to compile cocktails source with Caraulean framework   http://nuget.org/packages/Caliburn.Micro.Telerik - http://nuget.org/packages/Caliburn.Micro.Telerik
thanks
http://nuget.org/List/Packages/Caliburn.Micro.Telerik -



Replies:
Posted By: mgood
Date Posted: 15-Jan-2013 at 10:10am
No, there is no official sample. However, we have several customers that use Cocktail with Telerik. You don't need to compile Cocktail with Caliburn.Micro.Telerik. CMT is complimentary to CM and you can simply add it to your project, install the conventions by calling TelerikConventions.Install() in StartRuntime of your bootstrapper and replace the WindowManager with the TelerikWindowManager as documented here.
 
http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-application-bootstrapper#HReplacingthedefaultEventAggregator2CWindowManagerorDialogManager - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-application-bootstrapper#HReplacingthedefaultEventAggregator2CWindowManagerorDialogManager
 
You wouldn't use Alert, Confirm, Prompt as that functionality is provided by the Cocktail DialogManager.
 
http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-dialog-manager - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-dialog-manager
 
By replacing the default WindowManager with the TelerikWindowsManager, the DialogManager will use the RadWindow for the popups.
 
If you are doing WPF, I believe you will need to customize the dialog host XAML as documented here, because the default XAML uses Window, which the TelerikWindowManager will then attempt to wrap in a RadWindow.
 
http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-dialog-manager#HCustomizingthedialoghost - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-dialog-manager#HCustomizingthedialoghost
 
The default XAML looks like follows, so you want to change Window to RadWindow and make any other necessary changes.
 
<Window x:Class="Cocktail.DialogHostView"
        xmlns=" http://schemas.microsoft.com/winfx/2006/xaml/presentation - http://schemas.microsoft.com/winfx/2006/xaml/presentation "
        xmlns:x=" http://schemas.microsoft.com/winfx/2006/xaml - http://schemas.microsoft.com/winfx/2006/xaml "
        xmlns:cal=" http://www.caliburnproject.org - http://www.caliburnproject.org "
        xmlns:d=" http://schemas.microsoft.com/expression/blend/2008 - http://schemas.microsoft.com/expression/blend/2008 "
        xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 - http://schemas.openxmlformats.org/markup-compatibility/2006 "
        d:DesignHeight="277"
        d:DesignWidth="800"
        ResizeMode="NoResize"
        ShowInTaskbar="False"
        SizeToContent="WidthAndHeight"
        WindowStartupLocation="CenterOwner"
        WindowStyle="ToolWindow"
        mc:Ignorable="d">
    <Grid x:Name="LayoutRoot"
          MinWidth="166"
          Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ContentControl x:Name="ActiveItem"
                        IsTabStop="False"
                        TabIndex="0" />
        <ItemsControl x:Name="DialogButtons"
                      Grid.Row="1"
                      IsEnabled="{Binding ActionsEnabled}"
                      IsTabStop="False">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button MinWidth="75"
                            Margin="5"
                            Padding="2"
                            cal:Message.Attach="Close($dataContext)"
                            Content="{Binding Content}"
                            IsEnabled="{Binding Enabled}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</Window>


Posted By: mgood
Date Posted: 15-Jan-2013 at 11:56am
After I posted this I realized that you probably have to customize the XAML for Silverlight, too, if you develop for Silverlight. Both Window and ChildWindow are meant to be the root of a visual tree and don't behave properly as far as I remember if they are nested in another control.

It's been a while since I did this integration for a customer, so if you are running into trouble let me know. 


Posted By: decoda
Date Posted: 17-Jan-2013 at 4:18pm
Hi thanks the Main window shows up as a Radwindow, but when i call a dialog box i get an exception and cant trace were it is coming from, this is what i have done

AppBootstrapper

 public class AppBootstrapper : Cocktail.CocktailMefBootstrapper<ViewModels.MainWindowViewModel>
    {
        protected override void StartRuntime()
        {
            base.StartRuntime();
            StyleManager.ApplicationTheme = ThemeManager.FromName("Metro");
            TelerikConventions.Install();
        }
     
    }

MainWindowViewModel

 [Export]
    public class MainWindowViewModel : Screen
    {
        private readonly IDialogManager _dialogManager;
        private readonly NamePromptViewModel _namePrompt;

        [ImportingConstructor]
        public MainWindowViewModel(IDialogManager dialogManager, NamePromptViewModel namePrompt)
        {
            _dialogManager = dialogManager;
            _namePrompt = namePrompt;    

        }

        public void ShowDialog()
        {
            if (_dialogManager != null)
                _dialogManager.ShowMessageAsync("Are you sure?", DialogButtons.Ok, "test window");
        }

        public async void ShowPopup()
        {
            await _dialogManager.ShowDialogAsync(_namePrompt, DialogButtons.OkCancel);

            await _dialogManager.ShowMessageAsync(
            string.Format("Nice to meet you {0} {1}", _namePrompt.FirstName, _namePrompt.LastName),
             DialogButtons.Ok);
        }
      
    }


MainWindowView

<UserControl x:Class="telerikCocktail.Views.MainWindowView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="350" Width="525">
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Button x:Name="ShowPopup" Content="Popout" Grid.Row="0"></Button>
        <Button x:Name="ShowDialog" Content="Dialog" Grid.Row="1"></Button>
    </Grid>
</UserControl>

NamePromptViewModel

 [Export]
    public class NamePromptViewModel : Screen
    {
        private string _firstName;
        private string _lastName;

        public string FirstName
        {
            get { return _firstName; }
            set
            {
                _firstName = value;
                NotifyOfPropertyChange(() => FirstName);
            }
        }

        public string LastName
        {
            get { return _lastName; }
            set
            {
                _lastName = value;
                NotifyOfPropertyChange(() => LastName);
            }
        }
        
    }


NamePromptView

<UserControl x:Class="telerikCocktail.Views.NamePromptView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Grid.ColumnSpan="2" Margin="10" Text="Hello Stranger, what is your name?" />
        <TextBlock Grid.Row="1" Margin="10" VerticalAlignment="Center" Text="Firstname:" />
        <TextBlock Grid.Row="2" Margin="10" VerticalAlignment="Center" Text="Lastname:" />
        <TextBox x:Name="FirstName" Grid.Row="1" Grid.Column="1" Width="200" Margin="10" />
        <TextBox x:Name="LastName" Grid.Row="2" Grid.Column="1" Width="200" Margin="10" />
    </Grid>
</UserControl>


MyRadWindow

[Export(typeof(IWindowManager))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class MyRadWindow : TelerikWindowManager
    {
        public bool? ShowDialog(object rootModel, object context = null, IDictionary<string, object> settings = null)
        {
            return base.ShowDialog(rootModel, context, settings);
        }

        public void ShowWindow(object rootModel, object context = null, IDictionary<string, object> settings = null)
        {
            base.ShowWindow(rootModel, context, settings);
        }

        public void ShowPopup(object rootModel, object context = null, IDictionary<string, object> settings = null)
        {
            base.ShowPopup(rootModel, context, settings);
        }


    }


CustomDialogViewModel

    public class CustomDialogViewModel : DialogHostBase
    {
       
    }


CustomDialogView

<telerik:RadWindow x:Class="telerikCocktail.Views.CustomDialogView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cal="http://www.caliburnproject.org"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"
        d:DesignHeight="277" d:DesignWidth="800"
        ResizeMode="NoResize" SizeToContent="True"
        WindowStartupLocation="CenterOwner"  mc:Ignorable="d">
    <Grid x:Name="LayoutRoot"
          MinWidth="166"
          Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <ContentControl x:Name="ActiveItem"
                        IsTabStop="False"
                        TabIndex="0" />
        <ItemsControl x:Name="DialogButtons"
                      Grid.Row="1"
                      IsEnabled="{Binding ActionsEnabled}"
                      IsTabStop="False">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Width="75"
                            Height="23"
                            Margin="5"
                            cal:Message.Attach="Close($dataContext)"
                            Content="{Binding Content}"
                            IsEnabled="{Binding Enabled}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</telerik:RadWindow>




Posted By: mgood
Date Posted: 17-Jan-2013 at 4:30pm
What's the exception? The only thing that stands out at the moment is that your MainWindow is a UserControl and should be a RadWindow.


Posted By: decoda
Date Posted: 17-Jan-2013 at 4:59pm
I thought that the CustomDialogView will be used for mainwindow, i changed MainwindowView to radwindow but still the exception pops up

The Exception is :

{"Object reference not set to an instance of an object."}

System.Reflection.TargetInvocationException was unhandled by user code
  HResult=-2146232828
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  StackTrace:
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Activator.CreateInstance(Type type)
       at Caliburn.Micro.ViewLocator.<.cctor>b__2(Type viewType) in c:\Projects\Caliburn.Micro\src\Caliburn.Micro.Silverlight\ViewLocator.cs:line 300
       at Caliburn.Micro.ViewLocator.<.cctor>b__d(Type modelType, DependencyObject displayLocation, Object context) in c:\Projects\Caliburn.Micro\src\Caliburn.Micro.Silverlight\ViewLocator.cs:line 406
       at Caliburn.Micro.ViewLocator.<.cctor>b__e(Object model, DependencyObject displayLocation, Object context) in c:\Projects\Caliburn.Micro\src\Caliburn.Micro.Silverlight\ViewLocator.cs:line 440
       at Caliburn.Micro.TelerikWindowManager.CreateRadWindow(Object rootModel, Boolean isDialog, Object context, IDictionary`2 settings) in c:\Dev\cmt\WPF\Caliburn.Micro.Telerik\TelerikWindowManager.cs:line 67
       at Caliburn.Micro.TelerikWindowManager.ShowDialog(Object rootModel, Object context, IDictionary`2 settings) in c:\Dev\cmt\WPF\Caliburn.Micro.Telerik\TelerikWindowManager.cs:line 21
       at Cocktail.Dialog`1.Show()
       at Cocktail.DialogManager.ShowDialogAsync[T](IEnumerable`1 commands, Object content, String title)
       at Cocktail.DialogManager.ShowDialogAsync(Object content, IEnumerable`1 dialogButtons, String title)
       at Cocktail.DialogManager.ShowMessageAsync(String message, IEnumerable`1 dialogButtons, String title)
       at telerikCocktail.ViewModels.MainWindowViewModel.ShowDialog() in e:\code\Learning\newTutorial\Cocktail\telerikCocktail\telerikCocktail\ViewModels\MainWindowViewModel.cs:line 25
  InnerException: System.NullReferenceException
       HResult=-2147467261
       Message=Object reference not set to an instance of an object.
       Source=telerikCocktail
       StackTrace:
            at telerikCocktail.Views.CustomDialogView..ctor() in e:\code\Learning\newTutorial\Cocktail\telerikCocktail\telerikCocktail\Views\CustomDialogView.xaml.cs:line 18
       InnerException:



Posted By: decoda
Date Posted: 17-Jan-2013 at 5:04pm
Ah damn found the error sorry since i thought the  CustomDialogView will become the mainwindow i had put in the codebehind, thanks it working now

[CODE]
Application.Current.MainWindow = ((Window)this.ParentOfType<Window>());
Application.Current.MainWindow.ShowInTaskbar = true;
[CODE]


Posted By: mgood
Date Posted: 17-Jan-2013 at 5:11pm
Ok. Yeah from the exception it failed instantiating the view. I see you are doing Silverlight, so in that case the MainView should not be a RadWindow. I thought you were doing WPF. Change it back to UserControl. The CustomDialogView is only used for the popups.



Print Page | Close Window