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. Set style definition dynamically

Set style definition dynamically

Scheduled Pinned Locked Moved WPF
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.
  • S Offline
    S Offline
    salon
    wrote on last edited by
    #1

    I have abutton control, there are some style properties which can be set in App.xaml like this

    Style x:Key="ButtonStyle" TargetType="Button">
    <Setter Property="HorizontalAlignment" Value="Right"/>
    <Setter Property="Width" Value="50"/>
    <Setter Property="Height" Value="20"/>
    <Setter Property="VerticalAlignment" Value="Bottom"/>
    <Setter Property="Foreground" Value="Red"/>
    </Style>

    and give in button control as

    Style="{StaticResource ButtonStyle}"

    or in xaml.cs file as

    btnTest.Style = (Style)(Application.Current.Resources["ButtonStyle"]);

    But I want to generate this style dynamically and save it in a string and extract the style object from that string and apply it to the Button control. In other words I want to take style from a string not from App.xaml. Is it possible in Silverlight 2.0? Thanks in advance,

    M 1 Reply Last reply
    0
    • S salon

      I have abutton control, there are some style properties which can be set in App.xaml like this

      Style x:Key="ButtonStyle" TargetType="Button">
      <Setter Property="HorizontalAlignment" Value="Right"/>
      <Setter Property="Width" Value="50"/>
      <Setter Property="Height" Value="20"/>
      <Setter Property="VerticalAlignment" Value="Bottom"/>
      <Setter Property="Foreground" Value="Red"/>
      </Style>

      and give in button control as

      Style="{StaticResource ButtonStyle}"

      or in xaml.cs file as

      btnTest.Style = (Style)(Application.Current.Resources["ButtonStyle"]);

      But I want to generate this style dynamically and save it in a string and extract the style object from that string and apply it to the Button control. In other words I want to take style from a string not from App.xaml. Is it possible in Silverlight 2.0? Thanks in advance,

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

      You may find the info you need in this article: Silverlight White-labeling: "Dynamically" downloading and applying styles from a web server[^] Mark

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

      S 1 Reply Last reply
      0
      • M Mark Salsbery

        You may find the info you need in this article: Silverlight White-labeling: "Dynamically" downloading and applying styles from a web server[^] Mark

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

        S Offline
        S Offline
        salon
        wrote on last edited by
        #3

        I don't want to load the entire xaml file and store it. I want this file data inside a string for example:

        string s="<Style x:Key="ButtonStyle" TargetType="Button">
        <Setter Property="HorizontalAlignment" Value="Right"/>
        <Setter Property="Width" Value="50"/>
        <Setter Property="Height" Value="20"/>
        <Setter Property="VerticalAlignment" Value="Bottom"/>
        <Setter Property="Foreground" Value="Red"/>
        </Style>";

        and apply that like:

        btnTest.Style = (Style)(SOMETHING["ButtonStyle"]);

        What will be that SOMETHING...? How can I apply that ButtonStyle from the string s?

        M 1 Reply Last reply
        0
        • S salon

          I don't want to load the entire xaml file and store it. I want this file data inside a string for example:

          string s="<Style x:Key="ButtonStyle" TargetType="Button">
          <Setter Property="HorizontalAlignment" Value="Right"/>
          <Setter Property="Width" Value="50"/>
          <Setter Property="Height" Value="20"/>
          <Setter Property="VerticalAlignment" Value="Bottom"/>
          <Setter Property="Foreground" Value="Red"/>
          </Style>";

          and apply that like:

          btnTest.Style = (Style)(SOMETHING["ButtonStyle"]);

          What will be that SOMETHING...? How can I apply that ButtonStyle from the string s?

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

          salon wrote:

          I don't want to load the entire xaml file and store it.

          Right. I stated the article may have the info you need. You need a Style object from the XAML. That means the XAML has to be parsed - see the article. What are you trying to achieve that wouldn't be simpler with a few lines of code to create a Style dynamically? Mark

          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