Cannot edit RadWindow in Blend for VS2012

7 posts, 0 answers
  1. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 27 Mar 2013 Link to this post

    I'm using WPF RadControls Q3 2012 with VS2012. I need to make some changes to the RadGridView templates and I hoped to use Blend for VS2012 to help me with this. Blend for VS2012 doesn't support WPF projects until Update 2, so I've installed VS2012 Update 2 CTP 4 and Blend is now working with WPF projects.

    My project is using RadControls with implicit styles, to this end I have the following app.xaml.cs code behind

    public App()
    {
        InitializeComponent();
        SetTheme("Expression_Dark");
    }
     
    public void SetTheme(string themeName)
    {
        Resources.MergedDictionaries.Add(new ResourceDictionary()
        {
            Source = new Uri("/Telerik.Windows.Themes." + themeName + ";component/Themes/System.Windows.xaml",
               UriKind.RelativeOrAbsolute)
        });
     
        Resources.MergedDictionaries.Add(new ResourceDictionary()
        {
            Source = new Uri("/Telerik.Windows.Themes." + themeName +
                ";component/Themes/Telerik.Windows.Controls.xaml", UriKind.RelativeOrAbsolute)
        });
     
        // ... plus more merged resources
    }

    And in my Window class I have

    <tk:RadWindow x:Class="GridViewTesting.RadGridView.RadGridViewVw" x:ClassModifier="internal"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:tk="http://schemas.telerik.com/2008/xaml/presentation"
                  xmlns:rgv="clr-namespace:GridViewTesting.RadGridView"
                  Header="Telerik RadGridView Demo" Height="600" Width="500">
         
        <tk:RadWindow.Resources>
            <Style TargetType="rgv:RadGridViewVw" BasedOn="{StaticResource RadWindowStyle}"/>
        </tk:RadWindow.Resources>
     
        <!-- Controls defined here. -->
     
    </tk:RadWindow>

    But when I open this in Blend I get the error "The resource 'RadWindowStyle' could not be resolved."

    What's causing this and what's the best way to fix it please?
  2. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 27 Mar 2013 Link to this post

    Hi Bob,

    Blend does not execute Application constructor so RadWindowStyle won't be found.
    There are few approaches here.
    1. You could remove the explicit setting of Style property for RadWindow (or any other control) because you are using implicit styles and they will be applied anyway (if they are in the application resources).
    2. Or merge all your resources in App.xaml file. This way you Blend will be able to find RadWindowStyle.

    Keep in mind that if you choose the second approach Blend will use the resources added in the app.xaml so you won't be able to change the theme unless you set new resources in app.xaml.

    Let us know if you need more information.

    Regards,

    Hristo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 27 Mar 2013 Link to this post

    Removing the RadWindow.Resources Style results in the window not loading (Show or ShowDialog hang the application).

    This window subclasses RadWindow, and it seems that the styles which are implicitly defined for RadWindow will not be automatically picked up by this subclass without this declaration which inherits the RadWindow styles and implicitly applies them to this subclass. Is there a different way of doing this?
  5. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 01 Apr 2013 Link to this post

    Hi Bob,

    In WPF there is a strange behavior (to me this is a bug) where is you subclass control and don't override its DefaultStyleKey implicit styles for the base control won't be applied to the new one.
    There are two solutions to this problem:
    - create an implicit style (e.g. one without x:Key attribute placed in application the resources) and set its BasedOn property to point to RadWindowStyle
    - override the DefaultStyleKey property and set it to the type of your control. Then create an implicit style for this new control (it could be BasedOn original RadWindow style like in previous point)

    I hope this will help you.
    Let us know if you need more help.

    Kind regards,
    Hristo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 02 Apr 2013 Link to this post

    Can you clarify (ideally with an example) what you mean by "override the DefaultStyleKey" for a subclassed control please.

    After some experimentation I've found that I can subclass a Telerik control and have it set its own style properly using the following code:
    class SimpleRadGridView : Telerik.Windows.Controls.RadGridView
    {
        public SimpleRadGridView()
        {
            // Inherit the base classes style.
            Style baseStyle = (Style)FindResource("RadGridViewStyle");
            Style thisStyle =  new Style(typeof(SimpleRadGridView), baseStyle);
            Resources.Add(typeof(SimpleRadGridView), thisStyle);
        }
     
        // ...
    }

    As this new style is just inheriting from an existing App wide style how much overhead is incurred by this approach? Is there a better way to do it that does not require the client of this control to handle setting the style manually?
  7. Bob
    Bob avatar
    20 posts
    Member since:
    Mar 2012

    Posted 02 Apr 2013 Link to this post

    This also seems to work ok and is probably an improvement.

    class SimpleRadGridView : Telerik.Windows.Controls.RadGridView
    {
        static SimpleRadGridView()
        {
            // Inherit the base classes style.
            Style baseStyle = (Style)Application.Current.FindResource("RadGridViewStyle");
            Style thisStyle =  new Style(typeof(SimpleRadGridView), baseStyle);
            Application.Current.Resources.Add(typeof(SimpleRadGridView), thisStyle);
        }
     
        // ... rest of the implementation.
    }
  8. Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 05 Apr 2013 Link to this post

    Hi Bob,

    You are doing the same thing that the framework does for control styles. So in fact the easiest way would be to add one new Style with TargetType="{x:Type local:SimpleRadGridView}". No need to change defaultStyleKey or manually adding styles.I've attached simple project demonstrating how adding Style in App.Resources but with correct TargetType is enough to be applied. The demo targets control that inherits from RadWindow but the principle is the same for all inherited controls.

    I hope that this will help you.

    Greetings,
    Hristo
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
UI for WPF is Visual Studio 2017 Ready