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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:50:14+00:00 2026-05-17T00:50:14+00:00

I created the following xaml: <Button x:Name=PriceButton> <Button.Template> <ControlTemplate> <Border x:Name=ButtonBorder CornerRadius=2 Background={StaticResource DarkReflectionBrush}

  • 0

I created the following xaml:

 <Button x:Name="PriceButton">
  <Button.Template>
    <ControlTemplate>
      <Border x:Name="ButtonBorder"
                        CornerRadius="2"
                        Background="{StaticResource DarkReflectionBrush}"
                        BorderBrush="Black"
                        BorderThickness="1" HorizontalAlignment="Stretch">
          <ContentPresenter 
            VerticalAlignment="Center"
            HorizontalAlignment="Left">
          <ContentPresenter.Content>
            <Grid x:Name="ContentGrid" HorizontalAlignment="Left" >
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="15*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition  Width="15*"  />
              </Grid.ColumnDefinitions>
              <TextBlock x:Name="Price" Grid.Column="0" FontFamily="Calibri" FontSize="8" 
                         VerticalAlignment="Bottom" Text="{Binding Path=PriceText}"
                         Foreground="{Binding Path=PriceColor}" ></TextBlock>
              <TextBlock x:Name="Main" Grid.Column="1" FontFamily="Calibri" FontSize="14"
                         Text="{Binding Path=MainText}"
                         Foreground="{Binding Path=MainTextColor}" />
              <TextBlock x:Name="Vol" Grid.Column="2" FontFamily="Calibri" FontSize="8" 
                          VerticalAlignment="Bottom" Text="{Binding Path=VolatilityText}"
                         Foreground="{Binding Path=VolatilityColor}" />
            </Grid>
          </ContentPresenter.Content>
        </ContentPresenter>
      </Border>
      <ControlTemplate.Triggers>
        <Trigger Property="Button.IsPressed" Value="true">
          <Setter TargetName="ButtonBorder" Property="Background" Value="{StaticResource PressedBrush}"/>
        </Trigger>
        <Trigger Property="IsEnabled" Value="False">
          <Setter Property="Opacity" Value="0.5" />
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>
  </Button.Template>
</Button>

Here’s the Code Behind:

  public static readonly DependencyProperty PriceTextProperty =
  DependencyProperty.Register(
    "PriceText",
    typeof (string),
    typeof (LivePriceVolButton),
    new FrameworkPropertyMetadata(string.Empty, OnPriceTextChanged));

public string PriceText {
  get {
    return (string)GetValue(PriceTextProperty);
  }
  set {
    SetValue(PriceTextProperty, value);
  }
}

public static readonly DependencyProperty PriceColorProperty =
  DependencyProperty.Register(
    "PriceColor",
    typeof (Color),
    typeof (LivePriceVolButton),
    new FrameworkPropertyMetadata(Colors.White));

public Color PriceColor {
  get {
    return (Color) GetValue(PriceColorProperty);
  }
  set {
    SetValue(PriceColorProperty, value);
  }
}

public static readonly DependencyProperty MainTextProperty =
  DependencyProperty.Register(
    "MainText",
    typeof (string),
    typeof (LivePriceVolButton),
    new FrameworkPropertyMetadata(string.Empty));

public string MainText {
  get {
    return (string) GetValue(MainTextProperty);
  }
  set {
    SetValue(MainTextProperty, value);
  }
}

public static readonly DependencyProperty MainTextColorProperty =
  DependencyProperty.Register(
    "MainTextColor",
    typeof(Color),
    typeof(LivePriceVolButton),
    new FrameworkPropertyMetadata(Colors.White));

public Color MainTextColor {
  get {
    return (Color) GetValue(MainTextColorProperty);
  }
  set {
    SetValue(MainTextColorProperty, value);
  }
}

public static readonly DependencyProperty VolatilityTextProperty =
  DependencyProperty.Register(
    "VolatilityText",
    typeof(string),
    typeof(LivePriceVolButton),
    new FrameworkPropertyMetadata(string.Empty));

public string VolatilityText {
  get {
    return (string) GetValue(VolatilityTextProperty);
  }
  set {
    SetValue(VolatilityTextProperty, value);
  }
}

public static readonly DependencyProperty VolatilityColorProperty =
  DependencyProperty.Register(
    "VolatilityColor",
    typeof(Color),
    typeof(LivePriceVolButton),
    new FrameworkPropertyMetadata(Colors.White));

public Color VolatilityColor {
  get {
    return (Color) GetValue(VolatilityColorProperty);
  }
  set {
    SetValue(VolatilityColorProperty, value);
  }
}

When I insert my user control onto a form like this

 <my:LivePriceVolButton Margin="43.03,0,0,32" x:Name="livePriceVolButton1" 
                       xmlns:my="clr-namespace:MultiTextBlockButton" HorizontalAlignment="Left" 
                       Width="91.703" Height="30" VerticalAlignment="Bottom" 
                       MainText="MID" MainTextColor="LightBlue" PriceColor="Red" PriceText="1234.56"
                       VolatilityText="12.2%" VolatilityColor="Aqua" />

I don’t see anything in the button at all. Any ideas?

Thanks

  • 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-05-17T00:50:15+00:00Added an answer on May 17, 2026 at 12:50 am

    You have to set the DataContext for the Button to be equal to the parent UserControl for your Bindings to work. Try something like this:

    <UserControl x:Name="uc" ...>
    
      <Button x:Name="PriceButton" DataContext="{Binding ElementName=uc}">
        <!--Other code here...-->
      </Button>
    
    </UserControl>
    

    I also see that you’re using “Color” as the Type for some of your DependencyProperties. I suggest you change them to “Brush” instead. Otherwise the related bindings (e.g. Foreground=”{Binding VolatilityColor}”) won’t work.

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

Sidebar

Related Questions

I have created two buttons using the following XAML code. <Button x:Name=Button1 Width=100 Content=Button1
The following XAML code creates a button with a border as its content. The
Let's say I've created a UserControl with the following ContentTemplate defined in XAML: <UserControl.ContentTemplate>
I have a GridViewColumn created with the following XAML: <GridViewColumn Header=Validated > <GridViewColumn.CellTemplate> <DataTemplate>
I have the following XAML: <Grid x:Name=root> <Grid.RowDefinitions> <RowDefinition Height=*/> <RowDefinition Height=Auto/> </Grid.RowDefinitions> <Grid.Resources>
I've created a UserControl, similar to the following: <UserControl> <StackPanel Orientation="Vertical"> <StackPanel x:Name="Launch" Orientation="Horizontal"
I need the following alignment For that I have created the xaml file as
I created new WPF Application witn two windows. MainWindow.xaml Window1.xaml Added one button in
I've created the following XAML, approximately (shortened for brevity): <Window ... xmlns:Models=clr-namespace:Project.Presentation.Models;assembly=Project ...> <Window.Resources>
I have the following in xaml. <TextBlock Text={Binding Title} /> And created the following

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.