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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:19:24+00:00 2026-06-05T04:19:24+00:00

i want to design a flexible imagebutton in wpf. first,i create a WPF Custom

  • 0

i want to design a flexible imagebutton in wpf.
first,i create a WPF Custom Control Library in nameSpace ‘ImageButton’ like below:

namespace ImageButton
{

     public class ImageButton : Button
     {

         static ImageButton()
         {
              DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton), new FrameworkPropertyMetadata(typeof(ImageButton)));
         }


          #region DisplayMode
          [System.ComponentModel.Category("ImageButton")]

          public ImageDisplayMode DisplayMode
          {
              get { return (ImageDisplayMode)GetValue(DisplayModeProperty); }
              set { SetValue(DisplayModeProperty, value); }
          }

           public static readonly DependencyProperty DisplayModeProperty =
        DependencyProperty.Register("DisplayMode", typeof(ImageDisplayMode), typeof(ImageButton), new FrameworkPropertyMetadata(ImageDisplayMode.ImageAboveText), displaymodevalidate);

          public static bool displaymodevalidate(object value)
          {
                 return value is ImageDisplayMode;
          }


           #endregion

      }
}

in the namespace “ImageButton” i define a enum named ‘ImageDisplayMode’ like below:

public enum ImageDisplayMode
{
    ImageAboveText = 1,
    TextAboveImage = 2,
    ImageBeforeText = 3,
    TextBeforeImage = 4
}

and the Generic.xaml file modified like below:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ImageButton">
    <Style x:Name="style1" TargetType="{x:Type local:ImageButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ImageButton}">
                    <Button Background="Transparent">
                        <Grid>
                             <Grid.ColumnDefinitions>
                                  <ColumnDefinition/>
                                  <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                  <RowDefinition/>
                                  <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Image Grid.ColumnSpan="2" Name="img1" Width="{TemplateBinding ImageWidth}" Stretch="{TemplateBinding ImageStretch}" Height="{TemplateBinding ImageHeight}"  Source="{TemplateBinding Image}"/>
                            <TextBlock Grid.ColumnSpan="2" Grid.Row="1" Name="lbl1" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Text="{TemplateBinding Text}"/>

                        </Grid>
                    </Button>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

the result of above code is below figure:

[Image]
Text

i want:
when i change the value of ‘DisplayMode’ property of imagebutton,for each possible value ,control changes to below forms:

1————————————-
[Image]
Text

2————————————-
Text
[Image]

3————————————-
[Image]Text

4————————————–
Text[Image]

i guess ,i must define trigger in the grid in Generic.xaml codes like below:

<Grid.Triggers>
    <Trigger Property="DisplayMode" Value="2">
        <Setter Property="Grid.Row" TargetName="lbl1" Value="0"/>
        <Setter Property="Grid.Row" TargetName="img1" Value="1"/>
    </Trigger>
</Grid.Triggers>

please tell me :
How can i do it?

Thank you Very Much

  • 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-05T04:19:26+00:00Added an answer on June 5, 2026 at 4:19 am

    thanks fmunkert …
    I move my triggers to ControlTemplate.Triggers and change Trigger.Value from “2” to “ImageAboveText” ( one of my custom enum items ) like below:

    Before Edit:

     <Trigger Property="DisplayMode" Value="2"> 
         <Setter Property="Grid.Row" TargetName="lbl1" Value="0"/> 
         <Setter Property="Grid.Row" TargetName="img1" Value="1"/> 
     </Trigger> 
    

    After Edit:

     <Trigger Property="DisplayMode" Value="ImageAboveText">
         <Setter Property="Grid.Row" TargetName="lbl1" Value="0"/> 
         <Setter Property="Grid.Row" TargetName="img1" Value="1"/>
     </Trigger>
    

    my problem solved successfully….
    Thank you.

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

Sidebar

Related Questions

I want to create a timeline WPF control (as in this (http://www.taterboy.com/blog/images/MotionEditor/classic_vs_custom.png) kind of
I want to design a chat view like BlackBerry messenger (unfortunately new users are
This is what I'm trying to do: public class DataBuilder { public DataBlock create()
I want design a stored procedure / function creator program where user can create
I want to design a tab header. The html code is, <div class=tab-header> <a
I want to design a webpage as shown in the image below. There are
I want to design below view for the purpose to display it on Android
I want design my startup screen with progress bar. But I don't how to
I want to design a c# program which can run program a 3rd exe
We want to design a simple domain specific language for writing test scripts to

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.