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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:02:46+00:00 2026-05-30T02:02:46+00:00

Ive already been through about 30 different posts and changed how I handle this

  • 0

Ive already been through about 30 different posts and changed how I handle this and it gets closer but still wont work.

I have a Custom Button control in a library, that I am using in Main application. The button displays, handles mouse overs and such, but the dependency property for the text, (or Icon but Ill get to that later) wont update. When I set up the Dependency property with a default value that the only value it displays, it wont display anyhting I set in the designer, or through code.

       public static readonly DependencyProperty FileTextProperty;
   //Constructor
       static FileButton()
       {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(FileButton), new FrameworkPropertyMetadata(typeof(FileButton)));


        // Initialize dependency properties
        FileTextProperty = DependencyProperty.Register("FileText", typeof(string), typeof(FileButton),   new UIPropertyMetadata ("Default File Text")); 
        }

      /// <summary>
    /// The Filename text displayed by the button.
    /// </summary>
    [Description("The text displayed by the button."), Category("Common Properties")]
    public string FileText
    {
        get { return (string)GetValue(FileTextProperty); }
        set { SetValue(FileTextProperty, value); }
    }

here is the XAML (Somewhat abbreviated)

                    <Style x:Key="ButtonFocusVisual">
                        <Setter Property="Control.Template">
                            <Setter.Value>
                                <ControlTemplate>
                                    <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                    <Style x:Key="GradientStyle" TargetType="{x:Type Button}"> 
                        <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
                        <Setter Property="Background" Value="{StaticResource ButtonNormalBackground}"/>
                        <Setter Property="BorderBrush" Value="{StaticResource ButtonNormalBorder}"/>
                        <Setter Property="BorderThickness" Value="1"/>
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                        <Setter Property="HorizontalContentAlignment" Value="Center"/>
                        <Setter Property="VerticalContentAlignment" Value="Center"/>
                        <Setter Property="Padding" Value="1"/>
                        <Setter Property="Template">
                            <Setter.Value>

                                <ControlTemplate TargetType="{x:Type local:FileButton}">
                                    <Grid x:Name="main" MinHeight="38" MaxHeight="38">

                                        <Grid Margin="4,0" Name="DisplayMain">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition/>
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition/>
                                            </Grid.RowDefinitions>
                                            <TextBlock x:Name="fileText" HorizontalAlignment="Stretch" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=local:FileButton, AncestorLevel=1}, Path=FileText}" TextWrapping="NoWrap" VerticalAlignment="Top" Grid.Column="0" Margin="4,0,0,0" TextTrimming="WordEllipsis"/>
                                        </Grid>
                                    </Grid>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>

                </ControlTemplate.Resources>

                <Grid x:Name="LayoutRoot" Margin="0">
                    <local:FileButton Style="{DynamicResource GradientStyle}"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

When I run it the only data displayed on the button is the defaulted text. Even though I know I am setting the Dependency Property. I even when as far as using the binding Path=FileText.Length in the XAML to make sure its reaching it and it is, and it displayed 0 on the button, so it seems like Im not setting the data, even when I manually create the button, and insert it into a container, it still doesnt display what I set it to. (Yes I stepped into it in the debugger to make sure)

Any ideas, its been most of the day trying to figure this out.

PLEASE HELP 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-30T02:02:47+00:00Added an answer on May 30, 2026 at 2:02 am

    You don’t need to create a custom button for this. You can put any content you want inside a Button:

    <Grid x:Name="LayoutRoot">
        <Button VerticalAlignment="Top" Margin="132,140,168,0" Height="54.96">
            <StackPanel>
                <Image Source="{Binding Icon}"></Image>
                <TextBlock Text="{Binding FileName}" HorizontalAlignment="Left"/>
            </StackPanel>
        </Button>
    </Grid>
    

    Where FileName is a property in a viewmodel you create, which you set to be the DataContext of your Window (or grid or button).

    With this MVVM setup, when you change FileName in your code, it will automatically display it in your button.

    You can still style the button any way you want.

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

Sidebar

Related Questions

I'm sure this has already been asked and answered, but I honestly couldn't find
I've already referred to this SO post . I've been embedding images using an
I've been into this problem for a while already, and have asked some questions
I've already started similar topic , but still didn't find final solution... So here
I know there are plenty of questions here already about this topic (I've read
Okay i have already been through most of the ati and nvidia guides to
Apologies if this has already been asked and answered; I've looked around a bunch
I've been reading a lot about this since I've been asked to fix a
I've been a Delphi (D7) developer for many sometime already, I've always been wondering
I have a repository which I have already cloned from Subversion. I've been doing

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.