Is it possible to add more than one effect to a Label in Blend? - wpf

I'd like to have a label with a blur effect and a drop shadow effect.

If you use the older BitmapEffect, then you can make use of the BitmapEffectGroup:
<Label Content="Hello">
<Label.BitmapEffect>
<BitmapEffectGroup>
<DropShadowBitmapEffect />
<BlurBitmapEffect />
</BitmapEffectGroup>
</Label.BitmapEffect>
</Label>
BitmapEffect, however is being depreciated, and UIElement.Effect is the preferred method to add effects. To combine multiple behaviors into a Effect of this type, you will have to create a custom effect that does what you desire. As shown here, which will require more then just editing the elements through blend.
Also, take a look here: WPF Pixel Shader Effect Library
They have some exelent examples and pre-built effects as well as good tutorial on how to create your own.

It's a bit of a hack, but you could just wrap the label in a grid or border and apply the blur effect to that while applying the dropshadow to the label directly.

Related

Is there a way to create non-filled TextInputEditText with TextInputLayout in 1.1.0+?

I'm trying to migrate from Material components 1.0.0 to 1.1.0-alpha07 in order to be able to use ExposedDropdown style.
However, it messes up all my TextInputEditTexts as they are meant to be neither outlined nor filled.
I've tried setting TextInputEditText box backgrounds to transparent color, but that ends up making their fill completely white instead of making them see-through and exposing what's behind them (which is a brand color with gradient that spans more than the edit field, and that is why I can't just set its color to the background color as it just won't fit the gradient).
So, the question: Is there any way to keep the old-fashioned non-filled EditTexts in 1.1.0+ (while still using them inside TextInputLayout)?
Note:
I have to say that excluding a simple option to have edit fields non-filled (as they used to be) is a huge mistake since it almost completely shuts down painless migration to 1.1.0, you now basically have to force your design to change first.
Setting the TextInputEditText background to transparent worked for me.
My theme's parent is Theme.MaterialComponents.DayNight.DarkActionBar.
Another possibility is to use a ThemeOverlay for your editTextStyle:
<style name="Widget.YourTheme.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox>
<item name="materialThemeOverlay">#style/ThemeOverlay.YourTheme.TextInputEditText</item>
</style>
<style name="ThemeOverlay.YourTheme.TextInputEditText parent="ThemeOverlay.MaterialComponents.TextInputEditText.FilledBox">
<item name="editTextStyle">#style/Widget.YourTheme.TextInputEditText item>
</style>
<style name="Widget.YourTheme.TextInputEditText parent="Widget.MaterialComponents.TextInputEditText.FilledBox">
<item name="android:background">#android:color/transparent</item>
</style>
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.YourTheme.TextInputLayout"
...
<TextInputEditText>
...
</TextInputEditText>
</com.google.android.material.textfield.TextInputLayout>
I managed to find a rather simple answer to the problem.
The solution is to use app:boxBackgroundMode="none" with the filled box style.
You can also put an application-wide style for text input layouts (also applying the aforementioned attribute) using textInputStyle attribute in your app's theme and supplying the desired style.
As a side note, this just points out the catastrophic lack of easily-accessible documentation and guides that plagues this library.

How to mix text-only RibbonToggleButton and image-only RibbonButton in Ribbon for WPF?

I'm using the Microsoft Ribbon for WPF October 2010 and have got 3 buttons next to each other, inside a RibbonControlGroup. The left and the right ones are text-only RibbonToggleButton controls, the one in the middle is an image-only RibbonButton. The buttons have a defined width to match the row above.
My code:
<r:RibbonControlGroup>
<r:RibbonToggleButton Width="110" Label="Outgoing" IsChecked="True" />
<!-- Padding and Height set to align the buttons/image -->
<r:RibbonButton Width="30" Padding="5 0" Height="24" SmallImageSource="Images\Small\arrow_swap.png" />
<r:RibbonToggleButton Width="110" Label="Incoming" />
</r:RibbonControlGroup>
The problem is that as soon as I apply the SmallImageSource to the middle button, the other two get spacings for images, causing the text not to be centered anymore. That is problem (1).
Because I didn't find a quick solution, I tried to add the image of the middle button not via SmallImageSource, but by adding it as <Image> for the content of the button. However, the button would remain empty. That is problem (2).
My third solution was to add images to the left and the right button, too. Unfortunately there is nearly no margin between the image and text, which looks quite ugly. I tried several things to enlarge the margin like adding a <Style TargetType="Image"> to the <RibbonToggleButton.Resources>, but although the editor accepts it and displays the spacing at designtime, the margin is gone again at runtime. That is problem (3).
Does anybody have an appropiate solution to any of the three problems? I cannot get it to work. The number of the problems is also the preference of the alternatives, (1) being the most favourite to use with an appropiate hack.
It seems you cannot do that. Its by design.
As per MSDN (here about half way down the page):
Related ribbon controls can be grouped together in a RibbonControlGroup. When a control group is resized, one RibbonControlSizeDefinition is applied to all of the controls in the RibbonControlGroup. The RibbonControlGroup is positioned in the RibbonGroup as if it were one control.
All the controls in a RibbonControlGroup shares the same RibbonControlSizeDefinition. Hence, in your case image will be added for all the buttons.
You may use RibbonGroup instead if you do not want to glue all your controls very closely. This way you can customize each button container by using different RibbonControlSizeDefinitions.

Glossy shiny square button in WPF - XAML

I am trying to find rectangle buttons with gloss effect.
all examples are relevant for round buttons. (and when editing the code, the gloss effect is not suit the rectangle.
Do anyone know about xaml examples for button like in the images below?
It is possible to do this with XAML. There is a great XAML resource page for such things called xamalot.com. I have taken one button as a reference: http://xamalot.com/asset/0fc669c8-35f8-49c0-bceb-0d07f1d63691 :
The whole thing to draw with XAML is not that easy, but there are tools out there which allow you to draw and export like Microsoft's Expression Design.
The best way to accomplish this is with an image as content for the button.
<Button BorderThickness="0">
<Image Source="http://i.stack.imgur.com/XAgzU.jpg"/>
</Button>
You can use shading to get the effect in the second image or reflection to get the effect in the first image
You can create these kind of graphics with Illustrator easily, and Expression Blend has a feature to convert Illustrator vector files to XAML.
This option is the best in terms of quality, of course, since your graphics.
As an alternative, Expression Blend can do this too, maybe even faster.
I did do this type of thing once and I just drew the basic shape with a color, then drew another shape there, changed the scale + converted the shape to a path in Blend so I could move the points, then just applied a white color with lower alpha, and that's it.
I didn't provide much details in this answer so for any further information just leave me a comment.
Important tip: put your XAML graphics in a Viewbox!

WPF Text rendering problem

I created a custom control similar to TabControl. It works nice, except that the text in header items gets blury when I resize the content. It can, for example look like this:
Not only the text, but the box around the text can also get non-vertical. See the blue border around the "General" item:
What is causing this problem? I have set SnapToDevicePixels = True.
Thanks for any ideas!
EDIT:
I'm using .NET 4.0. TextOptions.TextFormattingMode is set to "Display".
The whole problem with fuzzy text and background occurs if I apply a DropShadowEffect effect in the style for ItemsControl which displays the buttons. This is the code for the Effect:
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Direction="0" ShadowDepth="1" BlurRadius="10" Opacity="0.2" Color="Black" />
</Setter.Value>
</Setter>
If this code is not enabled, the the text and the borders get displayed nicely.
I suspect you've said it yourself: SnapToDevicePixels will ruin text rendering if you've resized the text so it displays across pixels. You probably want to keep SnapToDevicePixels="True" on your borders/backgrounds, but turn it off for the text elements.
As for your border... can you post the xaml? I'm guessing that you're not using just a single element with rounded corners - are you drawing the edge of that tab as three separate lines?
There are 2 things to consider:
are you using .NET 3.5 or .NET 4.0? reason why I'm asking is that the text rendering has been changed between the versions. In 4.0 it's a lot better.
Sometime you have to wait a little while until the text get's sharper, so you scroll around, and then after a second the text becomes sharper. That could be as well a reason for you're issue.

How do you do relative positioning in WPF?

How can you relatively position elements in WPF?
The standard model is to use layout managers for everything, but what if you want to position elements (on a Canvas, for example) simply based on the position of other elements?
For example, you may want one element (say a button) to be attached the side of another (perhaps a panel) independent of the position or layout of that panel.
Anyone that's worked with engineering tools (SolidWorks, AutoCad, etc.) is familiar with this sort of relative positioning.
Forcing everything into layout managers (the different WPF Panels) does not make much sense for certain scenarios, where you don't care that elements are maintained by some parent container and you do not want the other children to be affected by a change in the layout/appearance of each other. Does WPF support this relative positioning model in any way?
Instead of putting (as in your example) a button directly on the canvas, you could put a stackpanel on the canvas, horizontally aligned, and put the two buttons in there.
Like so:
<Canvas>
<StackPanel Canvas.Left="100" Canvas.Top="100" Orientation="Horizontal">
<Button>Button 1</Button><Button>Button 2</Button>
</StackPanel>
</Canvas>
I think that it's quite flexible when you use more than 1 layout in a form, and you can create pretty much any configuration you want.
Good question. As far as I know, we need to have a different custom panel to get this feature. Since WPF is based on Visual Hierarchy there is no way to have this sort of Flat structure for the elements in the platform.
But Here is a trick to do this.
Place your elements in the same position and give relative displacement by using RenderTransform.TranslateTransform. This way your TranslateTransfrom's X and Y will always be relatuve to the other element.

Resources