Hi all
I am using the thememanager as follow:
using Infragistics.Themes;using Infragistics.Windows.Ribbon;namespace SapQmWp{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : XamRibbonWindow { public MainWindow() { InitializeComponent(); ThemeManager.ApplicationTheme = new Office2013Theme(); } }}
My question is, how can I change Textbox Background color with style?
Thanks
I've tried to follow:
I created two files
AzureTextBoxTheme.cs
public class AzureTextBoxTheme : ThemeBase { protected override void ConfigureControlMappings() { // Get the full name of the assembly where the theme's resource dictionaries are placed string assemblyFullName = Assembly.GetExecutingAssembly().FullName; Mappings.Add("System.Windows.Controls.TextBox", BuildLocationString(assemblyFullName, @"\AzureTextBoxTheme.xaml")); } }}
AzureTextBoxTheme.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SapQmWp.Themes"> <Style TargetType="{x:Type TextBox}"> <Setter Property="Background" Value="BlanchedAlmond"/> </Style> </ResourceDictionary>
And in the MainWindow.cs:
public partial class MainWindow : XamRibbonWindow { public MainWindow() { InitializeComponent(); ThemeManager.RegisterControl(typeof(TextBox)); ThemeManager.ApplicationTheme = new Office2013Theme(); } }
And in the xaml file, where I need to change the theme:
<ig:ThemeManager.Theme> <themes:AzureTextBoxTheme /> </ig:ThemeManager.Theme> <TextBox Grid.Column="0" Margin="{StaticResource MarginTen}" IsReadOnly="True" IsHitTestVisible="False" Text="{Binding Order}" />
But I've got an exception:
{"Cannot locate resource 'azuretextboxtheme.xaml'."}
How to inherent the textbox style from Office2013Theme?
Sorry it works.
Thanks so much.
First of all thanks so much for your response.
I want to set global wide font size and did as follow:
Style style = new Style(typeof(TextBox)) {BasedOn = (Style) FindResource(typeof(TextBox))};style.Setters.Add(new Setter(TextBox.FontSizeProperty, (double)26));Resources.Add(typeof(TextBox), style);
It does not work at all. Can you please help me.
Hi Jean-Pascal,
If you want to apply the style to not all TextBox but only a few of them you can add then explicitly the new style in the resources of the TextBoxes which you want to style or add the style directly in the parent FrameworkElement which contains them like this:
ThemeManager.ApplicationTheme = new Office2013Theme();
Style themeBasedStyle = (Style)FindResource(typeof(TextBox)); //Option 1 Style style = new Style(typeof(TextBox), themeBasedStyle); style.Setters.Add(new Setter(TextBox.BackgroundProperty, Brushes.BlanchedAlmond)); tb_Styled.Resources.Add(typeof(TextBox), style); //Option 2 Style style2 = new Style(typeof(TextBox), themeBasedStyle); style2.Setters.Add(new Setter(TextBox.BackgroundProperty, Brushes.Red)); sp_StyledViaStackPanel.Resources.Add(typeof(TextBox), style2);
I have also created a sample project which demonstrates both of these scenarios.
Please have a look at it and if you have any questions do not hesitate to ask.
Thanks,Teodor
Or can you please create an example project?
First of all thanks so much.
But how to apply several of Textboxs not to all Textboxs in the application?