How to increase the thickness of a `Slider` control - c#

I have a slider control in my grid:
<Slider x:Name="MainSlider"
Margin="659,145,417,146"
Grid.Row="1"
Orientation="Vertical"
SmallChange="1"
RenderTransformOrigin="0.0799999982118607,0.5"/>
I want it to be wider though, so that the whole bar is stretched out.
I've gone through the properties and Width doesn't actually change the thickness of the slider itself, just the frame.
How can I make the actual Slider thicker?

You will probably need to define your own style. You can copy the default style (using Expression Blend for example) and tweak the individual component values.
Use the "Edit Style" option to take a copy of the template and then work on that.
There's more information on MSDN

You can customize the style template of Slider as per your requirement:
http://codingsense.wordpress.com/2010/02/01/customize-a-slider-in-wpf-step-by-step-tutorial/
http://msdn.microsoft.com/en-us/library/vstudio/ms753256%28v=vs.90%29.aspx

If you make a template from a copy of the slider template:
Right-Click Slider->"Edit Template" -> "Edit a Copy"
Then you can change the TrackBackground and PART_SelectionRange WIDTH to whatever you want. They were "4.0" by default for my case:
<Border x:Name="TrackBackground"
Grid.Column="1"
Width="XX.X"
Margin="0,5"
HorizontalAlignment="center"
Background="{StaticResource HorizontalSliderTrackNormalBackground}"
BorderBrush="{StaticResource VerticalSliderTrackNormalBorder}"
BorderThickness="1"
CornerRadius="1">
<Canvas Margin="-1,-6">
<Rectangle x:Name="PART_SelectionRange"
Width="XX.X"
Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
Stroke="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}"
StrokeThickness="1.0"
Visibility="Hidden" />
</Canvas>
</Border>

Related

How to position "Selection Box" with ItemContainerStyle of a ListView?

I've been reading this documentation and I was wondering if it's possible to position the selection check box of the container? Specifically, this thing here:
Ideally, I want it aligned on the right. So far I've tried to use
<ListView.ItemContainerStyle>
<Style TargetType="WHAT DO I WRITE HERE?">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</ListView.ItemContainerStyle>
With various TargetTypes. Is it even possible to position that Selection-box?
To be honest you're looking in the wrong place. The ItemContainerStyle is adjust the margin padding and such properties of the container of the items of a listview.
What You need is a style for a ListViewItem. Lucky for us it's easily available from the ListViewItem styles and templates from the MSDN Documentation.
I won't paste the whole code here since, it's huge and it's cause deviated focus from the actual code that you need to tweak.
From the style from the above link, pick the second style of the two mentioned and refer to the below code:
<Border x:Name="MultiSelectSquare"
BorderBrush="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
BorderThickness="2"
Width="20"
Height="20"
Margin="12,0,0,0"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Visibility="Collapsed" >
<Border.Clip>
<RectangleGeometry Rect="0,0,20,20">
<RectangleGeometry.Transform>
<TranslateTransform x:Name="MultiSelectClipTransform"/>
</RectangleGeometry.Transform>
</RectangleGeometry>
</Border.Clip>
<Border.RenderTransform>
<TranslateTransform x:Name="MultiSelectCheckBoxTransform"/>
</Border.RenderTransform>
<FontIcon x:Name="MultiSelectCheck"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Glyph=""
FontSize="16"
Foreground="{ThemeResource SystemControlForegroundBaseMediumHighBrush}"
Visibility="Collapsed"
Opacity="0"/>
</Border>
The above code handles the checkbox kinda tick mark with border for SelectionMode="Multiple".
All the changes you want to do must be done in this style and the above code section of the style.
Please Note: I would advise not to play around with Visibility and Opacity property as they are modified using VisualStates. Don't worry about them they'll change states at runtime.

Change size of Progress Bar

I have progress bar but dots too small, how I can make it bigger?
I didnt found any property witch can change size of dots. Height/Width change onlly area where dots can move
Xaml code
<Grid // here width ="2560" height="1600"
<ProgressBar
Grid.Row="0"
Grid.Column="1"
IsIndeterminate="True"
Visibility="{Binding MainInstance.Loading, Converter={StaticResource BooleanToVisibilityConverter}}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"/>
</Grid
There are several options to solve this, it's up to you which one you pick:
Change the default style of ProgressBar and increase the Ellipse Width and Height properties. You can do this in Blend or by copying the style from
C:\Program Files (x86)\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\10.0.14393.0\Generic\generic.xaml
Use a ViewBox control to wrap around the ProgressBar. This control resizes all content to the available size.
Create a templated control with your own template settings properties.
I have created a small sample on GitHub to show you the code for all possibilities.
Easiest way to change ProgressBar's dots size is to use ScaleTransform:
<ProgressBar ...>
<ProgressBar.RenderTransform>
<ScaleTransform ScaleX="2" ScaleY="2" />
</ProgressBar.RenderTransform>
</ProgressBar>
In my case (WinUI3 SDK1.1.0) I have had a thin 1px-line and it helped me to use the MinHeight property instead of the Height. I hope that MinHeight also will help you with the dotted line.
<StackPanel BorderThickness="0" BorderBrush="LightGray" Padding="12">
<muxc:ProgressBar
Value="{x:Bind Path=XamlProductionViewModel.XamlCurrentProgress, Mode=OneWay}"
IsIndeterminate="{x:Bind Path=XamlProductionViewModel.XamlIsIndeterminate, Mode=OneWay}"
Visibility="{x:Bind Path=XamlProductionViewModel.XamlProgressVisibility, Converter={StaticResource booleanToVisibilityConverter}, Mode=OneWay}"
Foreground="AliceBlue"
Background="Transparent"
Minimum="0"
Maximum="100"
BorderThickness="0"
Margin="0"
MinHeight="25"
Width="300"/>
</StackPanel>
ProgressRing not support any property to change the dots width and height ,and when the ProgressRing have a bigger space the dots will be biggest.
You can use the Grid which get a ProgressBar and the Grid is permanent position.
You use the Grid.Row="0" Grid.Column="1" VerticalAlignment="Top" and you should write the code in Grid.You should give the Grid big space.
ProgressBar should use HorizontalAlignment="Stretch" and the same of VerticalAlignment.You have a big width and big height the dots will have a big width and big height.
<ProgressRing Margin="10,10,10,10"
IsActive="True"
Visibility="{x:Bind View.Visibility,Mode=OneWay}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" />
I write in the top Grid.You can see my app's ProgressRing have a big dots.
http://jycloud.9uads.com/web/GetObject.aspx?filekey=16bcfec973e910632e04b3990c274a1c

Modern UI WPF (mui) clickable logo

I am trying to find a way of making Modern UI WPF (MUI) logo clickable so I can initiate a web navigation to a certain page.
The idea is to change the MUI project the minimum necessary and not cause any dependency over my application.
The logo is defined in the ModernWindow style as follows:
<!-- logo (visible only when LogoData is not null) -->
<Border Grid.Column="2" Background="{DynamicResource Accent}" Width="36" Height="36" Margin="8,0"
DataContext="{TemplateBinding LogoData}"
Visibility="{Binding Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=inverse}">
<Path Data="{Binding}" Stretch="Fill" Fill="White" Width="24" Height="24" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
How can I wire the click event on this border to my application ModernWindow instance?
The simplest and, as far as I'm concerned the best way to implement click in your case:
Change your border by Button
Change your button's Style and ControlTemplate to make it look as you need
Define command binding to your view model, or implementation of Click event.
<Border ...>
...
<Border.InputBindings>
<MouseBinding Command="{Binding Path=MyClickCommand}" MouseAction="LeftClick" />
</Border .InputBindings>
</Border>

How to put an outlined textBlock (or any other control) in a TextBox

I am using this outlined textBlock that with the solution proposed by Javier G. works like a charm. I put it in a library so now it's HelperLib:OutlinedTextBlock.
Now I would like to put it in a TextBox.
So what I tried is:
Put the OutlinedTextBox as a child of a TextBlock but that didn't work since it's not accepting it as a child.
Use a RichTextBox and the put it inside a FlowDocument but something went wrong since a got a Runtime error
Use a template but again Runtime error.
If the fact of putting the outlinedTextBox makes it too peculiar I think that this can be rethought as putting anyother control inside a textbox.
I think the solution is close but somehow it still escapes me...
--EDIT--
There is an additiona problem which I have never encountered:
I have named my control otbQuery but it doesn't show up in the code!!! Why???
<TextBox Name="tbxQuery" VerticalAlignment="Center" Grid.Column="3" Width="200" Background="Transparent" CaretBrush="White" HorizontalAlignment="Center" Foreground="White" TextChanged="TextBox_TextChanged" BorderBrush="Gainsboro" BorderThickness="3">
<TextBox.Template>
<ControlTemplate>
<Border BorderBrush="Gainsboro" BorderThickness="3">
<Grid>
-----> <HelperLib:OutlinedTextBlock Name="otbQuery" Margin="1" Fill ="White" Stroke="Red" Text="{Binding Path=Content, ElementName=cp, Mode=OneWay}" VerticalAlignment="Center"/>
<ContentPresenter x:Name="cp" Content="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}" TextBlock.Foreground="Transparent"/>
</Grid>
</Border>
</ControlTemplate>
</TextBox.Template>
</TextBox>
you can see the error here and no valid quick fix is proposed
You will need to override the ControlTemplate of the TextBox control in order to make that happen. Below is a simple example of how to do that, and still have the TextBox.Text property bound to the Text property of the TexBlock.
<TextBox>
<TextBox.Template>
<ControlTemplate>
<Border BorderBrush="Black"
BorderThickness="1">
<Grid>
<TextBlock Margin="1"
Foreground="Red"
Text="{Binding Path=Content, ElementName=cp, Mode=OneWay}"/>
<ContentPresenter x:Name="cp"
Content="{Binding Text, RelativeSource={RelativeSource TemplatedParent}}"
TextBlock.Foreground="Transparent"/>
</Grid>
</Border>
</ControlTemplate>
</TextBox.Template>
</TextBox>
Where I have put a standard TextBlock inside the ControlTemplate, you would put your custom TextBlock control.
EDIT
The above solution works, but it's a serious kludge. Basically, it puts a transparent ContentPresenter on top of the TextBlock . The TextBlock display the text in the manner you want and the ContentPresenter allows you to type in the TextBox.
One problem that still exists is that the cursor bar does not show up when clicking on, or typing in the TextBox. I suspect that problem could be overcome with some more styling done to the template of the TextBox.

How to center Content in a Button Template and keep mouse events in empty area

I am using a Button Template to customize the look and feel of my buttons like so:
<ControlTemplate TargetType="Button">
<Border x:Name="Border" CornerRadius="6" BorderThickness="1">
<ContentPresenter Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True" ContentSource="Content"/>
</Border>
</ControlTemplate>
I want to center horizontally and vertically the Content, but when I do it the "empty" areas of the Button don't react to the Mouse. When I use Stretch the entire Button behaves alright, but the Content is aligned top-right.
How do I do both?
To make whole area of a Border hit test visible you need to initialise its Background property with some Brush. Can be even Transparent which will have same visual effect as default null.
<Border ... Background="Transparent" />

Categories

Resources