My problem is, I have different styles that are stored in the database table. I will select these styles and save them in some string variable. Now I want to apply this stylesheet to my wpf controls. so how can i do this?
Example:
My code ...
Window1.xaml
===========================
<Window x:Class="DynamicBindResourceDictionary.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Button Margin="103,64,68,86" Name="button1" Content="Click Here!" Style="{DynamicResource baseStyle}"></Button>
</Grid>
</Window>
Window1.xaml.cs
================
public partial class Window1 : Window
{
//Store the style here from database
string style = "<Style x:Key='baseStyle' TargetType='{x:Type Button}'>" +
"<Setter Property='FontSize' Value='15' />" +
"<Setter Property='Background' Value='Red' /></Style>";
public Window1()
{
InitializeComponent();
/* How to do that? */
}
}
if we cannot use a string variable than an alternative solution to this.
help me
Dharmesh
source
share