Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7962271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:17:41+00:00 2026-06-04T05:17:41+00:00

In App.xaml, I have the following code: <Application.Resources> <Style x:Key=LabelTemplate TargetType={x:Type Label}> <Setter Property=Height

  • 0

In App.xaml, I have the following code:

<Application.Resources>
    <Style x:Key="LabelTemplate" TargetType="{x:Type Label}">
        <Setter Property="Height" Value="53" />
        <Setter Property="Width" Value="130" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="Margin" Value="99,71,0,0" />
        <Setter Property="VerticalAlignment" Value= "Top" />
        <Setter Property="Foreground" Value="#FFE75959" />
        <Setter Property="FontFamily" Value="Calibri" />
        <Setter Property="FontSize" Value="40" />
    </Style>
</Application.Resources>

This is meant to provide a generic template for my labels.

In the main XAML code, I have the following line of code:

<Label Content="Movies" Style="{StaticResource LabelTemplate}" Name="label1" />

However, I’d like to initialize the Style property through code. I have tried:

label1.Style = new Style("{StaticResource LabelTemplate}");

and

label1.Style = "{StaticResource LabelTemplate}";

Neither solution was valid.

Any help would be appreciated :).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:17:44+00:00Added an answer on June 4, 2026 at 5:17 am

    Where in code are you trying to get the style? Code behind?

    You should write this:

    If you’re in code-behind:

    Style style = this.FindResource("LabelTemplate") as Style;
    label1.Style = style;
    

    If you’re somewhere else

    Style style = Application.Current.FindResource("LabelTemplate") as Style;
    label1.Style = style;
    

    Bottom note: don’t name a Style with the keyword Template, you’ll eventually end up confusing a Style and a Template, and you shouldn’t as those are two different concepts.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGrid style in App.xaml: <Style TargetType={x:Type DataGrid}> <Setter Property=Foreground Value={StaticResource DataGridItemTextBrush}
I have the following set of code in my App.xaml: <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary
I have the following custom defined Button defined in my App.xaml file. <Style x:Key=DispatchListCallButton
In App.xaml I have the following code: <Application xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml x:Class=FJW.App> <Application.Resources> <!-- Resources
I have the following App.xaml file: <Application x:Class=MiniDeviceConfig.App xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml StartupUri=MiniDeviceConfig.xaml> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries>
My situation is like following. I have a App.xaml which includes Style for ListView
I have the following code in my App.xaml.cs private void App_Start(object sender, StartupEventArgs e)
In my App.xaml file, I have the following code to allow double-decker column headers
I'm developing a Windows Phone app. I have the following XAML code: <Grid x:Name=ContentPanel
I have custom classes that I currently instantiate within App.xaml as resources. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.