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 9039799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:49:07+00:00 2026-06-16T09:49:07+00:00

I have created a button in Expression Blend 4. I want to dynamically create

  • 0

I have created a button in Expression Blend 4. I want to dynamically create instances of this button at run time.

The code for the button is below:

    <Button Content="Button" HorizontalAlignment="Left" Height="139" Margin="46,107,0,0" VerticalAlignment="Top" Width="412" Grid.ColumnSpan="2">
        <Button.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black"/>
                <GradientStop Color="White" Offset="1"/>
            </LinearGradientBrush>
        </Button.Background>
    </Button>

In addition to the supplying the code can you put comments in explaining what you are doing so that I can learn the general principle.

I know this is a simple question so I have been reading up places such as: Expression blend & WPF, Is there a way to "extract" WPF controls of Expression Blend?, and http://social.msdn.microsoft.com/forums/en-US/wpf/thread/ffa981b8-9bba-43a2-ab5e-8e59bc10fc0d/ unfortunately none of these have helped.

  • 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-16T09:49:09+00:00Added an answer on June 16, 2026 at 9:49 am

    In your WPF application you should have a App.xaml file, in there you can add Styles that are to be used thoughout your UI.

    Example:

    <Application x:Class="WpfApplication8.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
    
            <!--The style for all your buttons, setting the background property to your custom brush-->
            <Style TargetType="{x:Type Button}"> <!--Indicate that this style should be applied to Button type-->
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black"/>
                            <GradientStop Color="White" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Style>
    
        </Application.Resources>
    </Application>
    

    Or if you dont want to apply to all buttons, you can give your Style a Key so you can apply to certain Buttons in your UI

    <Application x:Class="WpfApplication8.App"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 StartupUri="MainWindow.xaml">
        <Application.Resources>
    
            <!--Add a x:Key value so you can use on certain Buttons not all-->
            <Style x:Key="MyCustomStyle" TargetType="{x:Type Button}"> 
                <Setter Property="Background">
                    <Setter.Value>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="Black"/>
                            <GradientStop Color="White" Offset="1"/>
                        </LinearGradientBrush>
                    </Setter.Value>
                </Setter>
            </Style>
    
        </Application.Resources>
    </Application>
    

    To use this Style on a Button, just add a binding to the Style property of the Button

      <Button Style="{StaticResource MyCustomStyle}" />
    

    this will apply the Style just to this Button

    Or if you really want to do it in code behind you can just add the Brush you want to the background

       Button b = new Button
       {
           Background = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 1), new Point(0.5, 0))
       };
    

    its very easy to translate xaml to code because xaml uses the exact same property names, like the code brush I posted above:

    new LinearGradientBrush(Colors.Black, Colors.White, new Point(0.5, 1), new Point(0.5, 0)) 
    

    is ….

    Brush(firstColor,secondColor,StartPoint EndPoint)
    

    Xaml just accesses properties in the button, they will all have the same names in C#.

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

Sidebar

Related Questions

I have created button 2 below: <input id=Button1 type=button value=Stop onclick=alert('hello world');/> <input id=Button2
I have created a button which I want to expand/contract. I found a way
i have created random expression and want to link their answers to the keypad
I have created button for home like this: UIBarButtonItem * addButton=[[UIBarButtonItem alloc] initWithTitle:@Home style:UIBarButtonItemStyleBordered
I have created several animations (storyboards) on different pages using Expression Blend. One case
I have created add button to create input field. Let me show you my
I have created radio button like this: @foreach (LoanQuestionIncludesStatement statement in item.Statements) { _question
I have created a button CSS class that uses background images with different positions
I have created a button in my Android application & I tried to set
I have created a button. So when I click the button it gives me

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.