Note that there are some explanatory texts on larger screens.

plurals
  1. POImageButton: image is not displayed when button disabled
    primarykey
    data
    text
    <p>I have created an UserControl to implement a simple <code>ImageButton</code> as following:</p> <pre><code>&lt;UserControl x:Class="MyApp.Common.Controls.ImageButton" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="UC"&gt; &lt;Grid&gt; &lt;Button Command="{Binding ElementName=UC, Path=Command}" CommandParameter="{Binding ElementName=UC, Path=CommandParameter}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="{Binding ElementName=UC, Path=Image}" Width="{Binding ElementName=UC, Path=ImageWidth}" Height="{Binding ElementName=UC, Path=ImageHeight}"/&gt; &lt;TextBlock Text="{Binding ElementName=UC, Path=Text}" /&gt; &lt;/StackPanel&gt; &lt;/Button&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>Here is code-behind of my control:</p> <pre><code>using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; namespace MyApp.Common.Controls { public partial class ImageButton : UserControl { public ImageButton() { InitializeComponent(); } public ImageSource Image { get { return (ImageSource)GetValue(ImageProperty); } set { SetValue(ImageProperty, value); } } public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(ImageButton), new UIPropertyMetadata(null)); public double ImageWidth { get { return (double)GetValue(ImageWidthProperty); } set { SetValue(ImageWidthProperty, value); } } public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register("ImageWidth", typeof(double), typeof(ImageButton), new UIPropertyMetadata(16d)); public double ImageHeight { get { return (double)GetValue(ImageHeightProperty); } set { SetValue(ImageHeightProperty, value); } } public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register("ImageHeight", typeof(double), typeof(ImageButton), new UIPropertyMetadata(16d)); public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(ImageButton), new UIPropertyMetadata("")); public ICommand Command { get { return (ICommand)GetValue(CommandProperty); } set { SetValue(CommandProperty, value); } } public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(ImageButton)); public object CommandParameter { get { return GetValue(CommandParameterProperty); } set { SetValue(CommandParameterProperty, value); } } public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register("CommandParameter", typeof(object), typeof(ImageButton)); } } </code></pre> <p>The usage is simple:</p> <pre><code> &lt;cc:ImageButton Command="{Binding SearchCommand}" Image="/MyApp;component/Images/magnifier.png" ImageWidth="16" ImageHeight="16" /&gt; </code></pre> <p>When the button (bound to DelegateCommand in my ViewModel) get disabled the image is disappear. Otherwise all works as expected. What could be a problem? How to make the image show in gray-scale when disabled? </p> <p><strong>UPDATE</strong>: here is the image of this strange behavior<img src="https://i.stack.imgur.com/wMlk9.png" alt="screenshot">:</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload