Get the current theme name at design time.

G

greg

Hi all,

Is there a way to get the current theme name at design time?

I'm trying to write a custom control for which I need to use images from the
current theme. I have asigned a theme to the page as well as in the
web.config.

The control looks ok at run time but when viewed in the Visual Studio
designer it cannot pick up the current theme.

Thanks in advance,
Greg.
 
V

Veerle

Hi all,

Is there a way to get the current theme name at design time?

I'm trying to write a custom control for which I need to use images from the
current theme. I have asigned a theme to the page as well as in the
web.config.

The control looks ok at run time but when viewed in the Visual Studio
designer it cannot pick up the current theme.

Thanks in advance,
Greg.

Page.Theme
 
J

Juan T. Llibre

re:
Is there a way to get the current theme name at design time?

You probably can get around this problem by building a string path to the correct directory.

You know all the themes reside under the App_Themes directory :


WebSite
\App_Themes
\ BlueTheme
Controls.skin
BlueTheme.css
\PinkTheme
Controls.skin
PinkTheme.css

If you set the Theme in the querystring :

Protected void Page_PreInit(object sender, EventArgs e)
{
switch (Request.QueryString["theme"])
{
case "Blue":
Page.Theme = "BlueTheme";
break;
case "Pink":
Page.Theme = "PinkTheme";
break;
}
}

....you can build a path to the correct directory you want to use for the images.

For a relative path to the directory for the current theme:

Page.AppRelativeVirtualPath + "/" & App_Themes + "/" + Request.QueryString["theme"]) +"/"

For the fully qualified path to the directory for the current theme :

string fullappname = Request.Url.Host
string fullpath = "http://" + fullappname + Request.ApplicationPath + "/" + App_Themes + "/" +
Request.QueryString["theme"])+"/"

Please double check the syntax, as I usually work in VB.NET...
 
G

Gregory Gasteratos

You probably can get around this problem by building a string path to the
correct directory.

You know all the themes reside under the App_Themes directory :
......
If you set the Theme in the querystring :


How would that work at design time?
I don think there is a way to set the query string while you are viewing
your page in Visual Studio (design time).
 
J

Juan T. Llibre

re:
!> I don think there is a way to set the query string while you are viewing
!> your page in Visual Studio (design time).

You wouldn't have to, would you ?

*You* don't need to know the path; the application's *users* do.

The code I posted ( which might need some checking, since C# isn't my strongest language )
assures that the *users* of the site get the correct path to the theme directory in use.

I assume that developers know what images they want to append to the path returned by that code.
 
G

greg

You wouldn't have to, would you ?
*You* don't need to know the path; the application's *users* do.

In my case I would, as my custom control uses a glyph that needs to be
displayed at design time as well as run time. That glyph is different
depending on the theme.
 
M

Mark Rae

In my case I would, as my custom control uses a glyph that needs to be
displayed at design time as well as run time. That glyph is different
depending on the theme.

But only you (i.e. the developer) sees design time... So long as everything
displays properly for your users (i.e. at run time), how can it possibly
matter to you whether something "looks nice" at design time...?
 
G

greg

But only you (i.e. the developer) sees design time... So long as
everything displays properly for your users (i.e. at run time), how can it
possibly matter to you whether something "looks nice" at design time...?

Developing a third paty control lybrary for others to use that wouldn't go
down very well.

I guess the question is not whether it matters to me or not. The question is
whether one can get the theme name at design time.

Digging into MSDN I found IThemeResolutionService and ThemeProvider. But I
couldn't find any example of how to use them.

Thanks for your replies.
Greg.
 
J

Juan T. Llibre

re:
!> my custom control uses a glyph that needs to be displayed at design time

Why ?

Design is design and runtime is runtime.
You can't expect runtime functionality at design time.

A similar example is using a querystring.

You don't need to see a querystring at design time.
You only need to be able to program against it.

re:
!> That glyph is different depending on the theme

I had gathered as much.
You'll have different glyphs in each theme's directory, right ?

Then, all you need to know is the path to the directory which contains
the specific glyph you're interested in displaying with the active theme.

I think what I outlined should suffice, and don't quite understand
why you'd need to actually see a glyph at design time.

At design time, themes are neither enabled nor displayed.
That's done at runtime.

As a developer, all you need to do is insure programmability.
If it works...that's all you need as a developer.
 
J

Juan T. Llibre

re:
!> Developing a third paty control lybrary for others to use that wouldn't go down very well.

Why not ?

Won't you will be supplying the different themes and glyphs ?
Won't you be placing them in the correct directories ?

If you design a control which displays different glyphs depending on which
theme is active, you can't expect your control's buyers to develop them, can you ?

re:
!> I guess the question is not whether it matters to me or not

Now I understand better, although If I had a choice between a control looking good
esthetically, at design time, and having a feature of a software product I wrote work
as expected at runtime, I'd definitely pick the latter.

But, it's your control and your approach should be determined by you.

I'm sorry if the solution I propose isn't appealing/acceptable to you.
It does work, though, and it has the right price.

:)
 
M

Mark Rae

Developing a third paty control lybrary for others to use that wouldn't go
down very well.

It wouldn't bother me in the slightest, as I (almost) never use Design view
anyway...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top