Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. How to use staticresource in .cs

How to use staticresource in .cs

Scheduled Pinned Locked Moved WPF
questioncsswpftutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    daveyerwin
    wrote on last edited by
    #1

    i have a RadialGradiantBrush in the app.xaml

    <Application.Resources>
    <RadialGradientBrush x:Name="RGB1">
    <GradientStop Color="AntiqueWhite" Offset="0.0" />
    <GradientStop Color="LightSalmon" Offset="0.25" />
    <GradientStop Color="LightBlue" Offset="0.75" />
    <GradientStop Color="Wheat" Offset="1.0" />
    </RadialGradientBrush>
    </Application.Resources>

    I assign it to a background in the generic.xaml

    <Canvas x:Name="RightCanvas" Grid.Column="2" Background = "{StaticResource RGB1}"/>

    How can i do this in the .cs file

    RightCanvas.Background = "{StaticResource RGB1}" as RadialGradiantBrush

    ? Thank you .

    M 1 Reply Last reply
    0
    • D daveyerwin

      i have a RadialGradiantBrush in the app.xaml

      <Application.Resources>
      <RadialGradientBrush x:Name="RGB1">
      <GradientStop Color="AntiqueWhite" Offset="0.0" />
      <GradientStop Color="LightSalmon" Offset="0.25" />
      <GradientStop Color="LightBlue" Offset="0.75" />
      <GradientStop Color="Wheat" Offset="1.0" />
      </RadialGradientBrush>
      </Application.Resources>

      I assign it to a background in the generic.xaml

      <Canvas x:Name="RightCanvas" Grid.Column="2" Background = "{StaticResource RGB1}"/>

      How can i do this in the .cs file

      RightCanvas.Background = "{StaticResource RGB1}" as RadialGradiantBrush

      ? Thank you .

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      RightCanvas.Background = Application.Current.Resources["RGB1"] as RadialGradientBrush;

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      D 1 Reply Last reply
      0
      • M Mark Salsbery

        RightCanvas.Background = Application.Current.Resources["RGB1"] as RadialGradientBrush;

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        D Offline
        D Offline
        daveyerwin
        wrote on last edited by
        #3

        Thanks Great, I have my brushes in app.xaml and now can access them from xaml or cs ! But now the designer doesnt work :( Error HRESULT E_FAIL has been returned from a call to a COM component. vs2008

        M 1 Reply Last reply
        0
        • D daveyerwin

          Thanks Great, I have my brushes in app.xaml and now can access them from xaml or cs ! But now the designer doesnt work :( Error HRESULT E_FAIL has been returned from a call to a COM component. vs2008

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          daveyerwin wrote:

          But now the designer doesnt work

          Since the Silverlight XAML designer is only partially implemented in VS, it can be "challenging" to find the offending code or markup :)

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups