WPF button text scrolling on mouse over - wpf

is it possible for buttons that have longer Content(text) than the max button width to kinda scroll the remaining text from right to left on mouse over? something like an electronic banner is the best I could explain it.
as of now this is the only thing that reflects my button style xaml.
<Page.Resources>
<Style x:Key="Str" TargetType="{x:Type Button}">
<Setter Property="Width" Value="90"/>
</Style>
</Page.Resources>

Yes. That's usually called marquee.
You can template a wpf control to do just about anything.
Put a canvas in there and a textblock. Animate the canvas.Left of the textblock.
There's a marquee implementation here:
https://social.technet.microsoft.com/wiki/contents/articles/31416.wpf-mvvm-friendly-user-notification.aspx?Redirected=true#Marquee
You would, obviously, want to start the animation using a datatrigger and ismouseover true.

Related

How to change ShowMessageAsync flow direction to "Right to Left"?

Is there any way to change Mahapps messagebox window (ShowMessageAsync)'s flow direction to Right to left ?
You can set the FlowDirection for the whole MetroWindow and all childrens.
FlowDirection="RightToLeft"
If you only want to set this to MessageDialog then you can change the style e.g. in your App.xaml like this
<Style TargetType="{x:Type Dialog:MessageDialog}"
BasedOn="{StaticResource {x:Type Dialog:BaseMetroDialog}}">
<Setter Property="FlowDirection" Value="RightToLeft" />
</Style>
So all message dialogs will get this style.
Hope this helps!
Overwriting the style should do it,
see: How to change MahApps.Metro dialog content template width?
The answer has a nice little tutorial.

WPF : Making a nice menu - how to make an animation on some focus?

I'm quite new to the "nice" WPF application and until now I was very focused on the architecture part(MVVM and stuff). I'm looking to improve this and I'm trying some things.
Currently I'm trying to do this kind of menu:
Every element on the left would be triggering some action to navigate on the part on the right.
What I'm currently failing to achieve is the green part, because I would like that now, if I click on "Settings", the green element "move" to settings(in fact, move to the bound SelectedItem.
I'm not sure what is my best option to achieve this?
Use a ListBox control. Style the ListBoxItem to set a particular colour for the HighlightBrushKey:
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green" />
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>

ListView Scrollbar Styling

I am working on a WPF project. I need to customize the horizontal scrollbar of Listview,like reducing its height,changing background etc. How do I achieve this?
Using this, doesn't seem to have any effect:
<ListView>
<ListView.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Height" Value="10"/>
</Style>
</ListView.Resources>
</ListView>
If you want to modify the width and height of the bars, you can take a look at this question, which points you in the direction of using System.Windows.SystemParameters to modify those values.
However I think you require more complex styling (e.g. change the background) so I'm afraid you will need to play with control template parts. Check these two links (found in the answer to this question):
Styling A ScrollViewer/Scrollbar In WPF
Styling the WPF ScrollViewer

WPF: Why are nested styles not always working?

I'm trying to apply a nested WPF style to a Toolbar. I'd like to have all children of the Toolbar (MenuItems, Buttons, ToggleButtons etc.) to have the specified style.
The problem is, that the nested style definition is applied correctly to some controls like MenuItems, but not to Buttons.
What am I doing wrong?
The MenuItem is correctly placed at the bottom of the Toolbar, but the ToggleButton is in the middle:
<Window.Resources>
<Style x:Key="MyToolbarStyle" TargetType="ToolBar">
<!-- Setters for Toolbar properties -->
<Setter Property="Height" Value="80" />
<!-- Nested setters for children of the Toolbar -->
<Style.Resources>
<Style TargetType="MenuItem">
<Setter Property="VerticalAlignment" Value="Bottom" />
</Style>
<Style TargetType="ToggleButton">
<Setter Property="VerticalAlignment" Value="Bottom" />
</Style>
</Style.Resources>
</Style>
</Window.Resources>
<Grid >
<ToolBar VerticalAlignment="Top" Style="{StaticResource MyToolbarStyle}">
<MenuItem Header="MyMenuItem" /> <!-- Appears on the bottom like defined in the style-->
<ToggleButton Content="MyToggleButton" /> <!-- Nested style does not seem to be applied-->
</ToolBar>
</Grid>
The WPF ToolBar is a special type of control that defines some custom styles for some WPF controls like Button, ToggleButton... full list here, you can identify them by ElementName + StyleKey property name. If you'd like to change a default style for a specific control you will have to modify one of these styles.
Try replacing your style for the ToggleButton with the following:
<Style x:Key="{x:Static ToolBar.ToggleButtonStyleKey}" TargetType="ToggleButton">
<Setter Property="VerticalAlignment" Value="Bottom" />
</Style>
What you are doing wrong is thinking that WPF Styles are like CSS styles. In WPF, Styles are just not used that way. Sure, if we could, we'd probably save a few lines of XAML, but we can't. The best that we can do is what you have done... I'm assuming that you've created a Style for a top level element like Control. As you have seen, not all controls will extend the Control class, so the Style won't be applied to all of them.
Instead, Styles in WPF are more like the .class styles in CSS... one Style per type and then we can apply a further Style per UI element. There are lots of situations like this in WPF where we wish we could write less code, but it is how it is and the sooner that everybody realises it, the better.
UPDATE >>>
In response to your first comment, you seem to be mistaken. Just to clarify, if what you are calling nested Styles are the Styles that you defined in the outer Style.Resources section, then there is nothing wrong with that... no problem what-so-ever. Just take those inner Styles out of the Resources section and you will see the same UI.
Now you're probably thinking of changing your question title to something like 'Why isn't my default ToggleButton Style being applied inside a ToolBar control?'. While I can't say for sure, I can only assume that this behaviour is caused by a Style that has been defined within the ToolBar ControlTemplate.
I'm thinking that because of the following points:
A custom implicit Style (no x:Key) will not work inside the ToolBar control.
A custom explicit Style (named) will work as expected inside the ToolBar control.
A Style property set on the element will work as expected inside the ToolBar control.

Changing glow speed in default WPF Button

The default WPF button we have in Visual Studio: when mouse hover on it, the button background will glow from grey to blue. The speed is too slow. How to speed up the glowing effect in XAML?
Is there something like below?:
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="GlowSpeed" Value="0.01" />
</Style>
Of course, this property doesn't exist. What property is that suppose to be? Is that some sort of Animation?
This animation is embedded in the default Template of the button, you would need to change the default template which can be found on MSDN (Default WPF Themes link).

Resources