Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6255871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:26:44+00:00 2026-05-24T14:26:44+00:00

In this Silverlight application, I am trying to access a resource from Application.Resources in

  • 0

In this Silverlight application, I am trying to access a resource from Application.Resources in a MainPage class. The resource has a x:Name attribute not a x:Key.

I know that I can assign a keyed resource from the Application.Resources by using the following line of code:

grid1.Background = (LinearGradientBrush)Application.Current.Resources["KeyedTwoColorGradient"];

Using this logic I tried to assign a named resource to my grid1.Background and used:

grid1.Background = ((LinearGradientBrush)Application.Current).Resources.NamedTwoColorGradient;

This line of code gives me an error:
Cannot convert type ‘System.Windows.Application’ to ‘System.Windows.Media.LinearGradientBrush’

I have tried also different lines but nothing has worked. I could not find the answer from somewhere else so I am here with this question.

In addition, could someone tell me when it would be appropriate to use Named resources and when it would be better to use Keyed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:26:45+00:00Added an answer on May 24, 2026 at 2:26 pm

    For starters your brackets were in the wrong place in your example (you were actually casting an application object to a LinearBrush) e.g.:

     ((LinearGradientBrush)Application.Current)
    

    but the “correct” syntax will auto-complete but will not compile:

    (Application.Current as App).KeyedTwoColorGradient;
    

    The problem is that there is no designer.cs equivalent for App.xaml, unlike user controls, so named members are only visible to intellisense but actually have no code-behind property.

    You should use keys only for resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop my first Silverlight navigation application. This application has 2 main
I'm trying to establish a HTTP persistent connection from a Silverlight application to a
i am now trying to display my arcgis map from c# silverlight application project
I'm trying to read a feed from Yahoo Pipes into a Silverlight Application. I
I have a Silverlight application that I am trying to style. This style simply
Inside my Silverlight 4.0 application (with elevated trust level), I'm trying to access the
I am trying to build an silverlight application which takes user first name, last
I'm currently trying to determine the available disk space from my Silverlight application. My
In MainPage.xaml.cs (Silverlight Application) I can do something like this: StackPanel myStackPanel = new
I'm writing a silverlight application that resembles a shopping cart system. This app can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.