Click here to Skip to main content
15,911,789 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Trigger Blend Storyboard from code behind. Pin
Pete O'Hanlon17-Mar-09 11:16
mvePete O'Hanlon17-Mar-09 11:16 
GeneralRe: Trigger Blend Storyboard from code behind. Pin
emptythetill17-Mar-09 11:36
emptythetill17-Mar-09 11:36 
GeneralRe: Trigger Blend Storyboard from code behind. Pin
Pete O'Hanlon17-Mar-09 11:41
mvePete O'Hanlon17-Mar-09 11:41 
QuestionValue Converter Work Around For Data Validation Pin
BlitzPackage17-Mar-09 5:11
BlitzPackage17-Mar-09 5:11 
AnswerRe: Value Converter Work Around For Data Validation Pin
Pete O'Hanlon17-Mar-09 5:52
mvePete O'Hanlon17-Mar-09 5:52 
GeneralRe: Value Converter Work Around For Data Validation Pin
BlitzPackage17-Mar-09 6:36
BlitzPackage17-Mar-09 6:36 
QuestionHow to set the background color of a particluar column in Silverlight? Pin
salon17-Mar-09 3:38
salon17-Mar-09 3:38 
QuestionWooHoo!!! Pin
Jammer17-Mar-09 2:49
Jammer17-Mar-09 2:49 
AnswerRe: WooHoo!!! Pin
Pete O'Hanlon17-Mar-09 3:00
mvePete O'Hanlon17-Mar-09 3:00 
GeneralRe: WooHoo!!! Pin
Jammer17-Mar-09 3:03
Jammer17-Mar-09 3:03 
QuestionSilverlight Pin
Ch.Gayatri Subudhi16-Mar-09 22:35
Ch.Gayatri Subudhi16-Mar-09 22:35 
AnswerRe: Silverlight Pin
Mark Salsbery17-Mar-09 10:13
Mark Salsbery17-Mar-09 10:13 
GeneralSilverlight Pin
Ch.Gayatri Subudhi17-Mar-09 18:10
Ch.Gayatri Subudhi17-Mar-09 18:10 
GeneralRe: Silverlight Pin
Mark Salsbery18-Mar-09 5:50
Mark Salsbery18-Mar-09 5:50 
QuestionWPF Control Name overwrite on initialization Pin
NoviceUser0916-Mar-09 22:19
NoviceUser0916-Mar-09 22:19 
Questioncreate chat room in WPF application Pin
psdeepu16-Mar-09 5:51
psdeepu16-Mar-09 5:51 
QuestionExport WPF ListView data to excel Pin
Pankaj Chamria16-Mar-09 3:52
Pankaj Chamria16-Mar-09 3:52 
AnswerRe: Export WPF ListView data to excel Pin
Eslam Afifi16-Mar-09 8:02
Eslam Afifi16-Mar-09 8:02 
GeneralRe: Export WPF ListView data to excel Pin
zameb30-Aug-10 23:00
zameb30-Aug-10 23:00 
Questioncreate a button dynamically Pin
anishkannan16-Mar-09 1:59
anishkannan16-Mar-09 1:59 
QuestionRe: create a button dynamically Pin
Mark Salsbery16-Mar-09 5:42
Mark Salsbery16-Mar-09 5:42 
AnswerRe: create a button dynamically Pin
anishkannan16-Mar-09 6:54
anishkannan16-Mar-09 6:54 
AnswerRe: create a button dynamically Pin
Eslam Afifi16-Mar-09 7:49
Eslam Afifi16-Mar-09 7:49 
Like this?

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="600" Width="300">
    <Grid>
        <Grid.Resources>
            <Style TargetType="{x:Type Button}">
                <Setter Property="Background" Value="Azure" />
            </Style>
        </Grid.Resources>

        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid.Children>
            <StackPanel x:Name="stack" />
            <Button HorizontalAlignment="Center" Grid.Row="1" Content="Add button" Click="Button_Click" />
        </Grid.Children>
    </Grid>
</Window>



using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = new Button() { Content = "Newly added button" };

            var rnd = new Random(DateTime.Now.ToBinary().GetHashCode());
            switch (rnd.Next(3))
            {
                case 0:
                    button.Background = Brushes.BlueViolet;
                    break;
                case 1:
                    var style = new Style();
                    style.Setters.Add(new Setter(Button.BackgroundProperty, Brushes.DarkBlue));
                    button.Style = style;
                    break;
            }

            stack.Children.Add(button);
        }
    }
}


Eslam Afifi

GeneralRe: create a button dynamically Pin
Eslam Afifi16-Mar-09 12:25
Eslam Afifi16-Mar-09 12:25 
GeneralRe: create a button dynamically Pin
anishkannan16-Mar-09 18:57
anishkannan16-Mar-09 18:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.