WPF: change style of progressbar - c#

How can I change the style of a progressbar in WPF?
On Windows 10 it's a straight bar, but in win 7 it's splitted in many small blocks. I want to have the bar straight as on win 10, when the application is used on win 7

I just lookng for a property like 'ugly-block-spacing' which I can set. Or do I have really define the whole style new?
Yes, I am afraid you will have to re-define the entire ControlTemplate from scratch. You cannot override only a part of a ControlTemplate:
WPF: Is there a way to override part of a ControlTemplate without redefining the whole style?
But you could copy the default ControlTemplate by right-clicking on a ProgressBar in design mode in Visual Studio on a Windows 10 computer, edit it as per your requirements and then use style i your application instead of the default one.

Progressbar has a property called Style, you could set it to your liking.

If you give Metro a try, you could use somthing like this:
<metro:MetroProgressBar x:Name="pbar" Value="50" Height="20"></metro:MetroProgressBar>
If you want to use the normal bar with Metro Style:
<ProgressBar x:Name="pbar" Value="50" Height="20" Style="{StaticResource MetroProgressBar}"></ProgressBar>
Same without Style:
<ProgressBar x:Name="pbar" Value="60" Height="20" Style="{x:Null}"></ProgressBar>
If you want to know more about Metro, you can find it here

Related

How to make the sidebar transition?

I have a simple splitview that has a rectangle of width 4px that indicates the selected item in the spiltview.
<Rectangle HorizontalAlignment="Left" VerticalAlignment="Top"
Width="4" Height="48" Margin="1,0"
Fill="{ThemeResource SystemAccentColor}" Grid.Row="2"
Visibility="{x:Bind btnHome.IsChecked, Mode=OneWay}"/>
Right now I've multiple rectangles turned on/off depending whether the checkbox is selected or not! But instead, I want a single rectangle in my code that should transition from the place where it previously was to place where the user has clicked.
Simplest for you would be using the new NavigationView if your minimum version is set to Fall Creators Update or use the HamburgerMenu control from UWP Community Toolkit (note that it's updated to use style very similar to yours, the docs aren't just updated with current screenshots). You can download the UWP Community Toolkit Sample App from Windows Store if you want to see how it currently looks.
If you want to use your custom solution, you should create a custom style or rather edit an existing style of the control you're using as hamburger menu items. Default styles are available for example here.

How to show slider tool tip?

Any one knows how to show the slider tool tip on Windows Phone 8.1 WinRT? I have checked the property IsThumbToolTipEnabled but no tool tip is shown. I couldn't find any resources on how to do this on phone. Any clue?
Set a custom template and use the tooltipservice api.
First, edit the style for a slider. Next find the <Thumb> Element. This code will work and show the text, and you can use binding for the text value.
<Thumb>
<ToolTipService.ToolTip>
<TextBlock Text="Your text"/>
</ToolTipService.ToolTip>
</Thumb>

Add ThumbToolTip to Slider

How to add a ThumbToolTip to a Slider (currently I'm working with Windows Phone 8.1 RT)?
According to MSDN - there is a property that should enable ThumbTooltip. But as I've looked at default style there is no sign of ToolTip.
I've tried to set the value to true (which is also a default value):
<Slider Maximum="100" Value="10" HorizontalAlignment="Stretch"
ThumbToolTipValueConverter="{StaticResource ToolTipConv}" IsThumbToolTipEnabled="True"/>
But no ToolTip was shown. I can think of making a Control and bind it to Slider's value, but can it be done easier way?
The default ThumbToolTip is not available for Windows Phone 8.1.
On Windows 10 UWP apps works fine.

Metro application directly focuses on my first field

I'm creating this test Metro application using Windows 8, VS2012, C# and XAML. There are different TextBox in the application page arranged in a StackPanel. When the application is launched the focus is on the first TextBox.
I was wondering how to "deactivate" this.
Here's a pic, as you can see the first field is focused (color changed and ToolTip displayed).
When your UI is loaded you can remove focus from the TextBox by applying a Programmatic focus state to any other control.
Imagine that you have a Button named myButton. You can:
myButton.Focus(FocusState.Programmatic);
You cannot however use FocusState.Unfocused state to remove focus from the TextBlock because it is not allowed and will throw an exception.
One simple fix for this is place something to catch it first with IsTabStop="True" with a 0 Opacity which is a bit hacky but the only way I know. So something like;
<TextBox IsTabStop="True" Opacity="0" Height="1" Width="1"/>
<!-- Then the rest of your content like your other TextBox stuff -->

Change background colour of TextBlock in C#

Currently porting an application to Windows Phone 7 I've encountered a problem that should be trivial
All I want is change the background colour of a TextBlock.
Using the WYSIWYG I can easily create a TextBlock, change the foreground and background colour.
So for a TextBlock using white text on black background I would use:
<TextBox Height="148" HorizontalAlignment="Left" Margin="106,0,0,0" Name="textBox1" Text="TextBox" VerticalAlignment="Top" Width="460" Background="Black" BorderBrush="Black" Foreground="White" />
But I need to do it in code (C#) and the Background doesn't appear to be a property of TextBlock.
How come it's something you can do using the resource editor, but not in code?
I've found various similar questions, but no definitive answer.
In Microsoft documentation (.Net), TextBlock does appear to have a Background property
Is there a way to do this in code without having to put the TextBlock inside a container (like Grid) which does have the Background property?
Thanks
JY
TextBlock is not inherited from Control, it doesn't have a Background property. The code you are showing is a TextBox not a TextBlock. TextBox inherites from Control and has a Background property. The simplest way is to wrap it with a Panel, or you can create a custom control for it.
Also, in silverilght sdk, you have a control called Label and it is inherited from Control. You can probably get the source code from there and implement it in your project.

Categories