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

Cannot edit RadWindow in Blend for VS2012

6 Answers 117 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 27 Mar 2013, 01:10 PM
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?

6 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 27 Mar 2013, 01:53 PM
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.

0
Bob
Top achievements
Rank 1
answered on 27 Mar 2013, 02:52 PM
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?
0
Hristo
Telerik team
answered on 01 Apr 2013, 07:15 AM
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.

0
Bob
Top achievements
Rank 1
answered on 02 Apr 2013, 03:49 PM
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?
0
Bob
Top achievements
Rank 1
answered on 02 Apr 2013, 03:55 PM
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.
}
0
Hristo
Telerik team
answered on 05 Apr 2013, 03:07 PM
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.

Tags
General Discussions
Asked by
Bob
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Bob
Top achievements
Rank 1
Share this question
or