Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does inheriting a WPF Button change the appearance of the image in a toolbar
    text
    copied!<p>Using the following code btn2 looks different to btn1 and btn3 yet they are using exactly the same image.</p> <pre><code>Public Class MyToolBar Inherits ToolBar Public Sub New() MyBase.New() Dim bmp1 = New BitmapImage(ImageUri.DeleteItem) Dim bmp2 = New BitmapImage(ImageUri.DeleteItem) Dim bmp3 = New BitmapImage(ImageUri.DeleteItem) Dim img1 = New Image With {.Source = bmp1} Dim img2 = New Image With {.Source = bmp2} Dim img3 = New Image With {.Source = bmp3} Dim btn1 = New Button With {.Content = img1} Dim btn2 = New MyButton With {.Content = img2} Dim btn3 = New Button With {.Content = img3} Me.AddChild(btn1) Me.AddChild(btn2) Me.AddChild(btn3) End Sub End Class Public Class MyButton Inherits Button End Class </code></pre> <p>The only difference in the code is btn2 is constructed with MyButton. MyButton is a simple inheritance of Button, no other code.</p> <p>btn1 &amp; btn3 appear as expected; flat. btn2 appears semi raised and has a black border.</p> <p>The order I add the buttons to the toolbar makes no difference. That is - the weird appearance of btn2 moves to the location that it is added to the toolbar.</p> <p>I've dumped and compared the properties, to 2 levels, of btn1 and btn2 and there is only the expected differences except for:</p> <p>btn1.DependencyObjectType.IsSecurityCritical=False btn2.DependencyObjectType.IsSecurityCritical=True</p> <p>and </p> <p>btn1.DependencyObjectType.IsSecurityTransparent=True btn2.DependencyObjectType.IsSecurityTransparent=False</p> <p>Anything else I should look into?</p>
 

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