Set style definition dynamically
-
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,
-
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,
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:
-
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:
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?
-
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?
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: