Good Evening Guys, I am new to WPF application. I have a trouble with Indeterminate progress bar design. I had researched a lot of progress bar related topic via online but I still not clear about the progress bar styling concept.
I had tried on changing the value of corner radius and set true for clip to bounds on every possible element that affected the corner radius (PART_Indicator,PART_Track,Indicator,Animation), but still no luck with this.
The Child Border always overlap it's parent. Shown as below
What I want to achieve on Progress bar shown as below.
Below is my code:
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="150">
<Grid>
<StackPanel Orientation="Vertical">
<ProgressBar Height="36" Name="progBar" VerticalAlignment="Top" IsIndeterminate="True" Foreground="Orange" BorderBrush="Gray" BorderThickness="1" >
<ProgressBar.Style>
<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar" >
<Grid Name="TemplateRoot" SnapsToDevicePixels="True">
<Rectangle RadiusX="2" RadiusY="2" Fill="Transparent" />
<Border CornerRadius="10" Margin="1,1,1,1">
<Border.Background>
<SolidColorBrush Color="Transparent"/>
</Border.Background>
</Border>
<Border BorderThickness="1" BorderBrush="gray" Margin="1,1,1,1" CornerRadius="10">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="White" Offset="0.0" />
<GradientStop Color="WhiteSmoke" Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
<Rectangle Name="PART_Track" Margin="1,1,1,1" ClipToBounds="True"/>
<Decorator Name="PART_Indicator" Margin="3,2,3,2" HorizontalAlignment="Left" ClipToBounds="True">
<Grid Name="Foreground" ClipToBounds="True">
<Rectangle RadiusX="10" RadiusY="10" Name="Indicator" ClipToBounds="True"/>
<Grid Name="Animation" ClipToBounds="True">
<Border Name="PART_GlowRect" Width="50" Margin="1" HorizontalAlignment="Left" Background="Orange" CornerRadius="10" />
</Grid>
<Grid Name="Overlay">
</Grid>
</Grid>
</Decorator>
<Border BorderThickness="0" CornerRadius="0" BorderBrush="Transparent" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ProgressBar.Style>
</ProgressBar>
</StackPanel>
</Grid>
</Window>
What had I did wrong on the code? Please for guide me regarding this issue.
Thank you.
Check out Clip property:
<Image
Source="sampleImages\Waterlilies.jpg"
Width="200" Height="150" HorizontalAlignment="Left">
<Image.Clip>
<EllipseGeometry
RadiusX="100"
RadiusY="75"
Center="100,75"/>
</Image.Clip>
</Image>
You can put any geometry inside Clip property. In your case it can be RectangleGeometry with RadiusX and RadiusY properties set.
More info: https://msdn.microsoft.com/ru-ru/library/system.windows.uielement.clip(v=vs.110).aspx
Thanks for Mikolaytis's answer, I am currently using RectangleGeometry.
I believe the Rect in RectangleGeometry it will not inherit the width from the parent width, I think I need to use code behind to recalculate the rect for different resolution.
I am sharing my code below in case somone facing the same issue as I was.
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="400">
<ProgressBar Height="36" Width="358" Name="progBar" VerticalAlignment="Top" IsIndeterminate="True" Foreground="Orange" BorderBrush="Gray" BorderThickness="1" >
<ProgressBar.Style>
<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar" >
<Grid Name="TemplateRoot" SnapsToDevicePixels="True">
<Rectangle RadiusX="2" RadiusY="2" Fill="Transparent" />
<Border CornerRadius="10" Margin="1,1,1,1">
<Border.Background>
<SolidColorBrush Color="Transparent"/>
</Border.Background>
</Border>
<Border BorderThickness="1" BorderBrush="Blue" Margin="1,1,1,1" CornerRadius="10">
<Border.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="Red" Offset="0.0" />
<GradientStop Color="Red" Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
<Rectangle Name="PART_Track" Margin="0" ClipToBounds="True" />
<Border Background="black" Name="PART_Indicator" Margin="0" HorizontalAlignment="Left" ClipToBounds="True">
<Border.Clip>
<RectangleGeometry Rect="2,2,354,32" RadiusX="9" RadiusY="9.5" />
</Border.Clip>
<Grid Name="Foreground">
<Rectangle RadiusX="10" RadiusY="10" Name="Indicator" ClipToBounds="True"/>
<Grid Name="Animation" ClipToBounds="True">
<Border Name="PART_GlowRect" Width="50" Margin="1" HorizontalAlignment="Left" Background="Orange" CornerRadius="10" />
</Grid>
<Grid Name="Overlay">
</Grid>
</Grid>
</Border>
<Border BorderThickness="0" CornerRadius="0" BorderBrush="Transparent" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ProgressBar.Style>
</ProgressBar>
</Window>
Related
I have providing a windows style for all of my windows:
Here is what I adding on app.xaml
<Style x:Key="Style.Window.Default" TargetType="Window">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Window">
<Grid Background="{TemplateBinding Background}">
<Grid Name="gridBar" Height="40" VerticalAlignment="Top" Margin="1,0,1,0">
<Grid.Background>
<LinearGradientBrush StartPoint="0, 0" EndPoint="0, 1" Opacity=".1">
<GradientStop Offset="0" Color="{DynamicResource AccentColor}" />
<GradientStop Offset=".3" Color="{DynamicResource AccentColor}" />
<GradientStop Offset="1" Color="Transparent" />
</LinearGradientBrush>
</Grid.Background>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- title -->
<ItemsControl Background="Transparent" MouseDoubleClick="MaximizeClick" >
<TextBlock Text="{TemplateBinding Title}" Margin="8,8,8,0" x:Name="txtTitle"
Style="{StaticResource ModernWindowTitle}"
/>
</ItemsControl>
</Grid>
<Grid VerticalAlignment="top" Margin="0,40,0,0" Background="White">
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
And here is what I have on each window:
<Window x:Class="WpfApplication1.MainWindow1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" Title="title"
Style="{StaticResource Style.Window.Default}" >
<Grid>
<TextBlock Text="text of window 1"></TextBlock>
</Grid>
</Window>
How could I change my code for having or showing data of Grid, because it's not showing data of the Grid
Use a content presenter to insert the content in the ControlTemplate. You never say where you want the content to appear, but this top-aligned grid is empty so maybe that's where?
<Grid VerticalAlignment="top" Margin="0,40,0,0" Background="White">
<ContentPresenter
/>
</Grid>
I have a question for you: What is the purpose of the ItemsControl here?
<!-- title -->
<ItemsControl Background="Transparent" MouseDoubleClick="MaximizeClick" >
<TextBlock Text="{TemplateBinding Title}" Margin="8,8,8,0" x:Name="txtTitle"
Style="{StaticResource ModernWindowTitle}"
/>
</ItemsControl>
Another question: Why do you define four columns in your grid and never use any of them? What are those columns for?
I have a custom textbox in WPF and I want to change its width while resizing it in designer view. I used Binding ActualHeight but it doesn't work.
As the picture shows I resized the TextBox in design mode but it is still in the same width, not changed. How can I change that control's Width(only) property according to resizing?
DottedTextBox
<UserControl x:Class="Easy_Message.DottedTextBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="400">
<Viewbox>
<TextBox x:Name="roottxt" Background="White"
BorderThickness="0" Width="{Binding ActualWidth,RelativeSource={RelativeSource TemplatedParent}}" Height="20">
<TextBox.Template>
<ControlTemplate TargetType="TextBox">
<Grid>
<Border x:Name="b" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
BorderThickness="1,0,1,0" BorderBrush="#c2c4cb">
<Border BorderThickness="0,1,0,0" BorderBrush="#9da0aa">
<Border BorderThickness="0,0,0,1" BorderBrush="#d9dae0">
<DockPanel>
<TextBox x:Name="orgbox" VerticalContentAlignment="Center"
HorizontalAlignment="Left"
BorderThickness="0"
FontSize="{TemplateBinding FontSize}"
Background="White"
Width="{Binding Path=Width,ElementName=b,Converter={StaticResource wconv}}" SelectionBrush="{TemplateBinding SelectionBrush}"
Height="20">
</TextBox>
<Border x:Name="brdDot" Background="{TemplateBinding Background}" Grid.Column="1"
Width="16" Height="{TemplateBinding Height}" HorizontalAlignment="Right"
BorderThickness="0">
<Canvas HorizontalAlignment="Right"
Width="10" Height="6"
Margin="0,0,2.5,2.5">
<Rectangle Width="1.5" Height="1.5" Fill="Black">
<Rectangle.RenderTransform>
<TranslateTransform X="0" Y="2"/>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Width="1.5" Height="1.5" Fill="Black">
<Rectangle.RenderTransform>
<TranslateTransform X="4" Y="2"/>
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Width="1.5" Height="1.5" Fill="Black">
<Rectangle.RenderTransform>
<TranslateTransform X="8" Y="2"/>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Border>
</DockPanel>
</Border>
</Border>
</Border>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=IsMouseOver, ElementName=brdDot}" Value="True">
<Setter TargetName="brdDot" Property="Background">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="White" Offset="-0.1"/>
<GradientStop Color="#ccdfff" Offset="0.6" />
<GradientStop Color="White" Offset="1.1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter TargetName="brdDot" Property="BorderThickness" Value="1,0,0,0" />
<Setter TargetName="brdDot" Property="BorderBrush" Value="#ccc9c9"/>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</TextBox.Template>
</TextBox>
</Viewbox>
I do not get selected item displayed in ComboBox ever since I have overwritten the default style with this one:
<LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="Blue" Offset="0.0"/>
<GradientStop Color="White" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<SolidColorBrush x:Key="WindowBackgroundBrush" Color="White" />
<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="ToggleButton">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="20" />
</Grid.ColumnDefinitions>
<Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="1" Background="#5089ba" BorderThickness="1" BorderBrush="White"/>
<Border Grid.Column="0" CornerRadius="1" Margin="1" Background="{StaticResource WindowBackgroundBrush}" BorderThickness="0,0,1,0" />
<Path x:Name="Arrow" Grid.Column="1" HorizontalAlignment="Center" Fill="White" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z"/>
</Grid>
</ControlTemplate>
<Style x:Key="{x:Type ComboBox}" TargetType="ComboBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton Name="ToggleButton" Template="{StaticResource ComboBoxToggleButton}" Grid.Column="2" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">
</ToggleButton>
<ContentPresenter Name="ContentSite" IsHitTestVisible="True" VerticalAlignment="Center" HorizontalAlignment="Center" />
<Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
<Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder" Background="{StaticResource WindowBackgroundBrush}" BorderThickness="1"/>
<ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
</Style.Triggers>
</Style>
Selection still works fine and does what it is supposed to do. It is just that I don't get the selected item displayed in header. What could be the reason?
This solved the problem:
<ContentPresenter Name="ContentSite" IsHitTestVisible="True" VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}"/>
I was missing the content template binding.
<ContentPresenter Name="ContentSite" IsHitTestVisible="True" VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding ComboBox.SelectionBoxItem}"
ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"/>
Now it will work ;)
IT's in your Content presenter.
You need to add a textblock.
<ContentPresenter Name="ContentSite" IsHitTestVisible="True" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text=" " />
</ContentPresenter >
These borders appear when they are clicked or hovered and don't go until the focus is lost.
There are borders on all four sides but since it is embedded in a shorter grid, the top and bottom ones are not visible.
How to remove these borders?
Please provide an example if possible.
XAML:
<Border x:Name="SearchBorder" BorderThickness="1" HorizontalAlignment="Left" Height="40" Margin="672,34,0,0" VerticalAlignment="Top" Width="355" Background="#3F000000">
<Border.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#4C000000" Offset="0"/>
<GradientStop Color="#3FFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Border.BorderBrush>
<Grid>
<TextBox x:Name="SearchBox" HorizontalAlignment="Left" Height="40" Width="296" Margin="10,0,0,0" TextWrapping="Wrap" VerticalAlignment="Center" SelectionBrush="Black" Background="#00000000" Foreground="#FF5B5B5B" FontSize="25" FontFamily="Segoe UI Light" BorderBrush="#00000000" CaretBrush="#FF6C6C6C"/>
<TextBlock HorizontalAlignment="Left" Height="23" Margin="320,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Center" Width="21" FontFamily="FontAwesome" FontSize="25" Foreground="#FF919191"/>
<Rectangle HorizontalAlignment="Left" Margin="311,-2,0,0" Width="1">
<Rectangle.Stroke>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#3F404040" Offset="0"/>
<GradientStop Color="#3F686868" Offset="1"/>
<GradientStop Color="#59DADADA" Offset="0.502"/>
</LinearGradientBrush>
</Rectangle.Stroke>
</Rectangle>
</Grid>
</Border>
Try BorderThickness="0"
<TextBox x:Name="SearchBox" BorderThickness="0" HorizontalAlignment="Left" Height="40" Width="296" Margin="10,0,0,0" TextWrapping="Wrap" VerticalAlignment="Center" SelectionBrush="Black" Background="#00000000" Foreground="#FF5B5B5B" FontSize="25" FontFamily="Segoe UI Light" BorderBrush="#00000000" CaretBrush="#FF6C6C6C"/>
you can remove the border by just setting the BorderBrush property to Transparent.
Normal View: Set the BorderBrush property to "Transparent"
<Button Name="BtnTest"
Content="Test"
BorderBrush="Transparent"
Height="20"
Width="75"/>
Hovering View: While you are hovering the control with mouse, Include these Control Template for Button or any control like Textbox or Textblock etc.. under the Window.Resources Tag
<Window.Resources>
<Style TargetType="Button">
<!--Default Values-->
<Setter Property="BorderBrush"
Value="Transparent"/>
<!--Transparent Highlight-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
i want to style my GridSplitter like adding dots on it (as found on http://msdn.microsoft.com/en-us/library/aa970265.aspx).
i also want to change gridsplitter color on mouseOver, or apply Aero Theme.
<Style x:Key="GridSplitterStyle1" TargetType="{x:Type GridSplitter}">
<Setter Property="Background"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="PreviewStyle">
<Setter.Value>
<Style>
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle Fill="#80000000"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridSplitter}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--Theme-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
<GridSplitter x:Name="gridSplitterTreeNodes" Width="10"
BorderThickness="1,0" Cursor="SizeWE"
RenderTransformOrigin="-1.2,0.507" ShowsPreview="True"
Style="{DynamicResource GridSplitterStyle1}">
<GridSplitter.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFE3EFFF" Offset="0"/>
<GradientStop Color="#FFAFD2FF" Offset=".45"/>
</LinearGradientBrush>
</GridSplitter.Background>
</GridSplitter>
Mostly for my own future reference, here is a vertical grid splitter that has the rounded shape of a button (but doesn't react to mouseover properly):
<GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Width="8">
<GridSplitter.Template>
<ControlTemplate TargetType="{x:Type GridSplitter}">
<Grid>
<Button Content="⁞" />
<Rectangle Fill="#00FFFFFF" />
</Grid>
</ControlTemplate>
</GridSplitter.Template>
</GridSplitter>
A horizontal splitter could just use "····" as the Button's Content.
<GridSplitter x:Name="gridSplitterTreeNodes" Width="5" BorderThickness="1,0"
Cursor="SizeWE" RenderTransformOrigin="-1.2,0.507" ShowsPreview="True"
Style="{DynamicResource GridSplitterStyle1}">
<GridSplitter.Background>
<ImageBrush ImageSource="Images\gripDots.png" TileMode="FlipXY"
Stretch="UniformToFill"/>
</GridSplitter.Background>
</GridSplitter>
You can also save image from Msnd Microsoft to get the same effect, More Info
Another way of adding a 'gripper' button/graphic to a GridSplitter, without losing mouse events, would be to use a simple label on top of the splitter.
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="Gray"/>
<Label Grid.Column="1" Content="⁞" Foreground="White" VerticalAlignment="Center" FontSize="26" FontWeight="Bold" IsHitTestVisible="False"/>
Making sure the GridSplitter and Label are in the same Column, and that IsHitTestVisible=False is set in the Label.
For a different type of style you can do the below.
Produces a nice overlaping style. The Gridsplitter overlaps both the left and right content.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="1"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="#777"/>
<GridSplitter
Grid.Column="1"
HorizontalAlignment="Stretch"
ResizeDirection="Columns"
ResizeBehavior="PreviousAndNext"
Panel.ZIndex="2">
<GridSplitter.Template>
<ControlTemplate TargetType="{x:Type GridSplitter}">
<Grid>
<Rectangle IsHitTestVisible="False" Fill="Black"/>
<Border
Background="White"
Width="25" Height="25" c
CornerRadius="25" Margin="-13 0">
<Path Stroke="Black" StrokeThickness="0.5" Width="17" Height="7" Data="m 4.4549201,1048.4664 -4.33056515,1.9095 4.33056515,1.9094 0,-3.8189 z m 3.0901599,0 0,3.8189 4.330565,-1.9094 -4.330565,-1.9095 z m -3.2239449,0.2053 0,3.4083 -3.86518514,-1.7041 3.86518514,-1.7042 z m 3.3577349,0 3.865185,1.7042 -3.865185,1.7041 0,-3.4083 z" Stretch="Fill"/>
</Border>
</Grid>
</ControlTemplate>
</GridSplitter.Template>
</GridSplitter>
<Border Grid.Column="2" Background="#777"/>
</Grid>
Sample Output
In response to Burton Radons's answer, I personally prefer the styling:
<GridSplitter
Width="8"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<GridSplitter.Template>
<ControlTemplate TargetType="{x:Type GridSplitter}">
<Grid>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="⁞" />
<Rectangle Fill="#00FFFFFF" />
</Grid>
</ControlTemplate>
</GridSplitter.Template>
</GridSplitter>
This implementation produces the same aesthetic effect whilst also maintaining functionality.