WPF glowing button - wpf

I have a WPF application. Where I have a toggle button that has a glass effect. When the button is checked the button fills blue which in the code below has been commented out. I have created a rectangle with a glow effect and would like this to be activated when the IsChecked = true. At the moment it doesn't appear to be doing anything.
<Style x:Key="ToggleButtonTemplate" TargetType="ToggleButton">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="FontSize" Value="12" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Margin" Value="5,5,5,5"/>
<Setter Property="IsChecked" Value="{Binding SecurityList[0].Run}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="ButtonBorder"
CornerRadius="15,15,15,15"
BorderThickness="3,3,3,3"
Background="#AA000000"
BorderBrush="#99FFFFFF"
RenderTransformOrigin="0.5,0.5">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="1.7*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Row="0" Grid.ColumnSpan="2" CornerRadius="23,23,0,0">
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#08FFFFFF" Offset="0"/>
<GradientStop Color="#88FFFFFF" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
<ContentPresenter x:Name="ButtonContentPresenter"
VerticalAlignment="Center"
Grid.RowSpan="2"
HorizontalAlignment="Center"/>
<Rectangle x:Name="recGlow" HorizontalAlignment="Left" Stroke="Black"
VerticalAlignment="Top" Opacity="0">
<Rectangle.Fill>
<RadialGradientBrush>
<RadialGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterY="0.5" CenterX="0.5" ScaleY="1.248" ScaleX="1.276"/>
<SkewTransform CenterY="0.5" CenterX="0.5"/>
<RotateTransform CenterY="0.5" CenterX="0.5"/>
<TranslateTransform Y="0.317" X="-0.007"/>
</TransformGroup>
</RadialGradientBrush.RelativeTransform>
<GradientStop Color="#FF088CE8" Offset="0"/>
<GradientStop Offset="1"/>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Text="GBP / USD" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="SemiBold"/>
<Image Grid.Row="1" Grid.Column="0" Source="/Resources/GBP.ico"/>
<Image Grid.Row="1" Grid.Column="1" Source="/Resources/USD.ico"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<!--<Setter TargetName="ButtonBorder" Property="Background" Value="Blue"/>-->
<Setter TargetName="recGlow" Property="Opacity" Value="0.8"/>
<Setter Property="RenderTransform" TargetName="ButtonBorder">
<Setter.Value>
<TransformGroup>
<ScaleTransform ScaleX="1.1" ScaleY="1.1"/>
</TransformGroup>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

Rectangle is too small to be observed.
Set HorizontalAlignment and VerticalAlignment to Stretch and set Grid.ColumnSpan to 2 on rectangle -
<Rectangle x:Name="recGlow" HorizontalAlignment="Stretch" Stroke="Black"
VerticalAlignment="Stretch" Opacity="0" Grid.ColumnSpan="2">

Related

ToolTip appears Instantly in WPF. Does not trigger Initial delay

I have two buttons in Main.Xaml. I declare ToolTip for each of them. They have a very small gap which is barely visible with open eyes but still they have gap which you you can see by their Margin.
<Button
Style="{StaticResource RoundCorner}"
x:Name="button1" Width="71" HorizontalAlignment="Left" Margin="165,14,0,0" Height="24"
VerticalAlignment="Top" UseLayoutRounding="True" RenderOptions.ClearTypeHint="Enabled" RenderOptions.BitmapScalingMode="NearestNeighbor" SnapsToDevicePixels="True"
>
<Button.Content >
<TextBlock FontSize="10" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" Margin="0,-2,0,0" >
Settings
</TextBlock>
</Button.Content>
<Button.ToolTip >
<ToolTip Style="{StaticResource ToolTipDefaults}" UseLayoutRounding="True" RenderOptions.ClearTypeHint="Enabled" RenderOptions.BitmapScalingMode="NearestNeighbor" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display"
>
<StackPanel>
<TextBlock FontFamily="Segoe UI" FontSize="12" TextOptions.TextFormattingMode="Display" >
Settings
</TextBlock>
</StackPanel>
</ToolTip>
</Button.ToolTip>
</Button>
`enter code here`<Button
Style="{StaticResource RoundCorner}"
x:Name="button2" Width="71" HorizontalAlignment="Left" Margin="237,14,0,0" Height="24"
VerticalAlignment="Top" UseLayoutRounding="True" RenderOptions.ClearTypeHint="Enabled" RenderOptions.BitmapScalingMode="NearestNeighbor" SnapsToDevicePixels="True"
>
<Button.Content >
<TextBlock FontSize="10" FontFamily="Segoe UI" UseLayoutRounding="True" TextOptions.TextFormattingMode="Display" Margin="0,-2,0,0" >
Settings
</TextBlock>
</Button.Content>
<Button.ToolTip >
<ToolTip Style="{StaticResource ToolTipDefaults}" UseLayoutRounding="True" RenderOptions.ClearTypeHint="Enabled" RenderOptions.BitmapScalingMode="NearestNeighbor" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display"
>
<StackPanel>
<TextBlock FontFamily="Segoe UI" FontSize="12" TextOptions.TextFormattingMode="Display" >
Settings
</TextBlock>
</StackPanel>
</ToolTip>
</Button.ToolTip>
</Button>
I have created two control template one is for button which is consider as "RoundCorner" and declare as StaticResource of buttons in Main.XAMl. And another is for ToolTip.
Here is the Code for RoundCorner Controltemplate(Button) --
<Style x:Key="RoundCorner" TargetType="{x:Type Button}" x:Name="RoundCornerButton" >
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Foreground" Value="#bababa" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid" >
<Border x:Name="border" CornerRadius="1" BorderThickness="0" >
<Border.Background>
<RadialGradientBrush GradientOrigin="0.496,1.052">
<RadialGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterX="0.5" CenterY="0.5"
ScaleX="1.5" ScaleY="1.5"/>
<TranslateTransform X="0.02" Y="0.3"/>
</TransformGroup>
</RadialGradientBrush.RelativeTransform>
<GradientStop Offset="1" Color="#282828"/>
<GradientStop Offset="0.3" Color="#282828"/>
</RadialGradientBrush>
</Border.Background>
<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center"
>
</ContentPresenter>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="border" Value="#202020"/>
<Setter Property="Foreground" Value="WhiteSmoke" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" TargetName="border">
<Setter.Value>
<RadialGradientBrush GradientOrigin="0.496,1.052">
<RadialGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.5" ScaleY="1.5"/>
<TranslateTransform X="0.02" Y="0.3"/>
</TransformGroup>
</RadialGradientBrush.RelativeTransform>
<GradientStop Color="#161616" Offset="1"/>
<GradientStop Color="#161616" Offset="0.3"/>
</RadialGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Here is the Control template code for Tooltip--
<Style x:Key="ToolTipDefaults" x:Name="NewTooltip"
TargetType="{x:Type ToolTip}">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="HasDropShadow"
Value="True" />
<Setter Property="ToolTipService.Placement"
Value="MousePoint" />
<Setter Property="ToolTipService.VerticalOffset"
Value="5" />
<Setter Property="ToolTipService.HorizontalOffset"
Value="-10" />
<Setter Property="Foreground"
Value="#606060"/>
<Setter Property="ToolTipService.InitialShowDelay"
Value="1000" />
<Setter Property="ToolTipService.BetweenShowDelay"
Value="0" />
<Setter Property="ToolTipService.ShowDuration"
Value="6000" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToolTip}">
<Grid x:Name="grid" Margin="10" >
<Border x:Name="Bordermini" HorizontalAlignment="Right"
BorderThickness="0.5"
Width="{TemplateBinding Width}"
Height="15">
<Border.Background>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="White"
Offset="0.0" />
<GradientStop Color="White"
Offset="1.0" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="Gainsboro" />
</Border.BorderBrush>
<Border.Effect>
<DropShadowEffect Opacity="0.8" BlurRadius="5" Direction="-82" ShadowDepth="3.8" Color="#282828" >
</DropShadowEffect>
</Border.Effect>
<ContentPresenter Margin="1.5,0"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
</Border>
<Border x:Name="Border" HorizontalAlignment="Right"
BorderThickness="0.5"
Width="{TemplateBinding Width}"
Height="19">
<Border.Background>
<LinearGradientBrush StartPoint="0,0"
EndPoint="0,1">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#ffffff"
Offset="0.0" />
<GradientStop Color="#ffffff"
Offset="1.0" />
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<Border.BorderBrush>
<SolidColorBrush Color="Gray" />
</Border.BorderBrush>
<ContentPresenter Margin="4,0"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" Value="True" >
<Setter TargetName="Border"
Property="CornerRadius"
Value="0" />
<Setter TargetName="Border"
Property="SnapsToDevicePixels"
Value="true" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
So, How I re trigger the initial delay as soon as I quickly move the mouse cursor from one button to another? Is there any need to use the "Datatrigger" or "DataBinding" to overcome this issue?
1:Open the Nuget of your package,search and add YshXaf.DevExpress.Mvvm_yesfree and YshXaf.DevExpress.Xpf.Core_yesfree.
2:Add below class and using DevExpress.Mvvm.UI.Interactivity for it.
public class ToolTipBehavior : Behavior<FrameworkElement>
{
private object _popupControlService;
private PropertyInfo _toolTipTimerProperty;
protected override void OnAttached()
{
base.OnAttached();
var popControlServiceProperty = typeof(FrameworkElement).GetProperty("PopupControlService", BindingFlags.Static | BindingFlags.NonPublic);
_popupControlService = popControlServiceProperty.GetValue(this.AssociatedObject);
_toolTipTimerProperty = _popupControlService.GetType().GetProperty("ToolTipTimer", BindingFlags.Instance | BindingFlags.NonPublic);
this.AssociatedObject.ToolTipClosing += AssociatedObject_ToolTipClosing;
}
void AssociatedObject_ToolTipClosing(object sender, ToolTipEventArgs e)
{
_toolTipTimerProperty.SetValue(_popupControlService, new DispatcherTimer());
}
protected override void OnDetaching()
{
base.OnDetaching();
}
}
3: Add xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" in the Xaml.Then use the ToolTipBeahvior in your RoundCorner.
<Setter Property="dxmvvm:Interaction.BehaviorsTemplate">
<Setter.Value>
<DataTemplate>
<ContentControl>
<local:ToolTipBehavior/>
</ContentControl>
</DataTemplate>
</Setter.Value>
</Setter>
Here is the result picture:

How to set another control style when they are created in ItemsControl

The following shows two buttons. When the mouse is over the second button, I would like to change the firsts borderbrush to white.
<ItemsControl ItemsSource="{Binding Path=ModuleCollection}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid Margin="0">
<Button Content="{Binding ModuleName}" Template="{StaticResource navModuleButton}"/>
<Button Template="{StaticResource CloseButtonStyle}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I believe could possibly be done with a datatrigger on the first button as follows, but in order to do that I need to name the second button, not sure how to dynamically name.
<DataTrigger Binding="{Binding ElementName=closeBtn1, Path=IsMouseOver}" Value="True">
<Setter Property="BorderBrush" TargetName="btnBorder" Value="#FFFFFFFF"/>
</DataTrigger>
How to do this?
[EDIT]
This is the template for the first button where you'll see btnBorder is the border I would like to change the color of.
<ControlTemplate x:Key="navModuleButton" TargetType="{x:Type Button}">
<Border x:Name="btnBorder" RenderTransformOrigin="0.5,0.5" BorderThickness="1,1,1,1" CornerRadius="0,0,7,0">
<Grid x:Name="Grid" RenderTransformOrigin="0.5,0.5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Border x:Name="Border1" RenderTransformOrigin="0.5,0.5" BorderThickness="0.5,0.5,0.5,0.5" CornerRadius="0,0,7,0">
<Border.Background>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1" />
<RotateTransform Angle="90" />
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>
</Border.Background>
</Border>
<DockPanel Name="myContentPresenterDockPanel">
<ContentPresenter x:Name="myContentPresenter" Margin="10,0,21,0"
Content="{TemplateBinding Content}"
HorizontalAlignment="Center" VerticalAlignment="Center"
TextBlock.Foreground="White" />
</DockPanel>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" TargetName="btnBorder" Value="#FFFFFFFF"/>
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsEnabled" Value="False"/>
</MultiTrigger.Conditions>
<Setter Property ="Opacity" Value="0.30" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsPressed" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Border1">
<Setter.Value>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<TranslateTransform X="0" Y="0"/>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="90"/>
<TranslateTransform X="0" Y="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#837C7C7C" Offset="0"/>
<GradientStop Color="#83343434" Offset="0.99496336996337187"/>
<GradientStop Color="#83343434" Offset="0.523844744998591"/>
<GradientStop Color="#837C7C7C" Offset="0.48045224006762494"/>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Cursor" Value="Hand" TargetName="Grid"/>
<Setter Property="BitmapEffect" TargetName="Border1">
<Setter.Value>
<OuterGlowBitmapEffect GlowColor="Blue"/>
</Setter.Value>
</Setter>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
You can use the SourceName property in a trigger, like this:
<DataTemplate>
<Grid Margin="0">
<Button x:Name="btnModule"
Content="{Binding ModuleName}"
Template="{StaticResource navModuleButton}"/>
<Button x:Name="btnClose"
Template="{StaticResource CloseButtonStyle}"/>
</Grid>
<DataTemplate.Triggers>
<Trigger SourceName="btnClose" Property="IsMouseOver">
<Setter TargetName="btnModule" Property="BorderBrush" Value="White"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
Don't worry about the names, WPF takes care of that, since the DataTemplate has it's own Name Scope
Edit: your button ControlTemplate is wrong.
A ControlTemplate should be defined in such a way that the properties of the Visual elements inside of it are "tied" to the properties of the Control the template is applied to.
In other words, your btnBorder should depend on the properties of the "parent templated item" the Control to which template is applied, in this case, btnModule.
For that purpose, a common approach is to use a TemplateBinding in the ControlTemplate, like this:
<Border x:Name="btnBorder"
RenderTransformOrigin="0.5,0.5"
BorderThickness="1,1,1,1"
CornerRadius="0,0,7,0"
BorderBrush="{TemplateBinding BorderBrush}"> <!-- See the TemplateBinding here -->
this will bind the btnBorder.BorderBrush property to the parent's BorderBrush (in this case btnModule.BorderBrush)

Removing gloss from progressbar?

So I was suggested to use WPF forms to make a custom UI for my applications. The first thing I wanted to try was to change the look of the progress bar. The only thing holding me back from it's new look atis the glossy effect over the top of it. I want the progrss bar to be made of mostly solid colours. Is there anyway to remove the glossy part of the progress bar?
Shown here:
Thanks.
Nasreddine answers is very good but if you want something simpler you can use the following
<Style TargetType="{x:Type ProgressBar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Border BorderBrush="#D9DCE1" BorderThickness="1" Background="#E8E8E8" CornerRadius="0" Padding="0">
<Grid x:Name="PART_Track">
<Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" Fill="#FF49A3E1" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
You can achieve any style you want by editing the ControlTemplate of the progress bar. Here's an example :
Disclaimer: I'm not a designer.
<!-- Brushed used by the progress bar style -->
<LinearGradientBrush x:Key="ProgressBarIndicatorAnimatedFill" EndPoint="0,0" MappingMode="Absolute" StartPoint="-100,0">
<GradientStop Color="#00000000" Offset="0"/>
<GradientStop Color="#FF000000" Offset="0.4"/>
<GradientStop Color="#FF000000" Offset="0.6"/>
<GradientStop Color="#00000000" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="ProgressBarTopHighlight" Color="#80FFFFFF" />
<!-- progress bar style -->
<Style x:Key="FlatProgressBar" TargetType="{x:Type ProgressBar}">
<Setter Property="Foreground" Value="#01D328"/>
<Setter Property="Background" Value="#C7C7C7"/>
<Setter Property="BorderBrush" Value="#B2B2B2"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid x:Name="Background" SnapsToDevicePixels="true">
<Rectangle Fill="{TemplateBinding Background}" RadiusY="2" RadiusX="2"/>
<Border Background="{x:Null}" CornerRadius="2" Margin="1"/>
<Border BorderBrush="#80FFFFFF" BorderThickness="1,0,1,1" Background="{StaticResource ProgressBarTopHighlight}" Margin="1"/>
<Rectangle x:Name="PART_Track" Margin="1"/>
<Decorator x:Name="PART_Indicator" HorizontalAlignment="Left" Margin="1">
<Grid x:Name="Foreground">
<Grid.ColumnDefinitions>
<ColumnDefinition MaxWidth="15"/>
<ColumnDefinition Width="0.1*"/>
<ColumnDefinition MaxWidth="15"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Rectangle x:Name="Indicator" Grid.ColumnSpan="3" Fill="{TemplateBinding Foreground}" Grid.RowSpan="2"/>
<Rectangle x:Name="Animation" Grid.ColumnSpan="3" Fill="{TemplateBinding Foreground}" Grid.RowSpan="2">
<Rectangle.OpacityMask>
<MultiBinding>
<MultiBinding.Converter>
<Themes:ProgressBarHighlightConverter/>
</MultiBinding.Converter>
<Binding Source="{StaticResource ProgressBarIndicatorAnimatedFill}"/>
<Binding ElementName="Background" Path="ActualWidth"/>
<Binding ElementName="Background" Path="ActualHeight"/>
</MultiBinding>
</Rectangle.OpacityMask>
</Rectangle>
</Grid>
</Decorator>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="LayoutTransform" TargetName="Background">
<Setter.Value>
<RotateTransform Angle="-90"/>
</Setter.Value>
</Setter>
<Setter Property="LayoutTransform" TargetName="PART_Track">
<Setter.Value>
<RotateTransform Angle="90"/>
</Setter.Value>
</Setter>
<Setter Property="LayoutTransform" TargetName="PART_Indicator">
<Setter.Value>
<RotateTransform Angle="90"/>
</Setter.Value>
</Setter>
<Setter Property="LayoutTransform" TargetName="Foreground">
<Setter.Value>
<RotateTransform Angle="-90"/>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsIndeterminate" Value="true">
<Setter Property="Visibility" TargetName="Indicator" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsIndeterminate" Value="false">
<Setter Property="Fill" TargetName="Animation" Value="#80B5FFA9"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Apply this style to your ProgressBar and you're good to go :
<ProgressBar Style="{StaticResource FlatProgressBar}" Value="50" />
Here's the end result :

Visual corruption around rounded corners

In my WPF app, I see these smear-like visual corruptions, especially around rounded corners. Notice the problem with the upper corners of the button.
I tried the following but the issue persists:
SnapToDevicePixels=true
Resized and moved the app window.
Changed the screen resolution
What might be causing this?
XAML for the button:
<Button Width="Auto" Click="btnAdd_Click" Height="Auto" x:Name="btnAdd" VerticalAlignment="Center" HorizontalAlignment="Right" Focusable="False" Margin="20,0,0,0" SnapsToDevicePixels="True">
<StackPanel Orientation="Horizontal" Margin="0">
<TextBlock Text="Ekle" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,5,0"/>
<Image Source="/FideKiosk;component/Icons/right.png" MaxWidth="30" Width="15" Height="15"/>
</StackPanel>
</Button>
and then I have an implicit style in Application.Resources:
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid">
<Rectangle RadiusX="10" RadiusY="10" x:Name="rectangle" Opacity="0.995">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="0" Color="#FFC0F3AD" Opacity="0"/>
</Rectangle.Effect>
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.501,0.039" StartPoint="0.501,0.971">
<GradientStop Color="#FF346223" Offset="0.124" />
<GradientStop Color="#FF325625" Offset="0.526" />
<GradientStop Color="#FF39622B" Offset="0.534" />
<GradientStop Color="#FF367021" Offset="0" />
<GradientStop Color="#FF4A8535" Offset="0.986" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" Margin="15" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" TargetName="grid" Value="0.5"/>
</Trigger>
<Trigger Property="IsMouseCaptureWithin" Value="True">
<Setter Property="Effect" TargetName="rectangle">
<Setter.Value>
<DropShadowEffect BlurRadius="30" Color="#FFC0F3AD" Opacity="1" ShadowDepth="0"/>
</Setter.Value>
</Setter>
<Setter Property="Fill" TargetName="rectangle">
<Setter.Value>
<LinearGradientBrush EndPoint="0.501,0.039" StartPoint="0.501,0.971">
<GradientStop Color="#FF346223" Offset="0.303"/>
<GradientStop Color="#FF325625" Offset="0.526"/>
<GradientStop Color="#FF39622B" Offset="0.534"/>
<GradientStop Color="#FF4A8535" Offset="0"/>
<GradientStop Color="#FF8AC077" Offset="0.986"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I used your code and could not find any artifacts in neither the designer nor when running the app. So unless you have more UI elements that are not in code you presented my guess is that the graphics card (hardware/driver) on your machine is causing this.
You could test this by switching to software rendering: Can I force WPF rendering tier?

WPF Infinite loop in references found while processing the Template

I am pretty new to WPF and am getting this error after my mouse is over my custom listbox item.
Error: Infinite loop in references found while processing the Template for an element named '' of type 'System.Windows.Controls.TextBox'.
<Window.Resources>
<ControlTemplate x:Key="MouseOverFocusTemplate" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="55*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Width="290" TextAlignment="Left" VerticalContentAlignment="Center" BorderThickness="0" BorderBrush="Transparent"
Foreground="#FF6FB8FD"
FontSize="24"
TextWrapping="Wrap"
Text="{Binding .}"
Grid.Column="1"
Grid.Row="1"
MinHeight="55"
Cursor="Hand"
IsReadOnly="True"
FontFamily="Arial"
>
<TextBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF013B73" Offset="0.501"/>
<GradientStop Color="#FF091F34"/>
<GradientStop Color="#FF014A8F" Offset="0.5"/>
<GradientStop Color="#FF003363" Offset="1"/>
</LinearGradientBrush>
</TextBox.Background>
</TextBox>
</Grid>
</ControlTemplate>
<Style x:Key="MouseOverFocusStyle" TargetType="{x:Type TextBox}">
<Setter Property="Template" Value="{StaticResource MouseOverFocusTemplate}"/>
</Style>
<ControlTemplate x:Key="LostFocusTemplate" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="55*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Width="290" TextAlignment="Left" VerticalContentAlignment="Center" BorderThickness="0" BorderBrush="Transparent"
Foreground="#FF6FB8FD"
FontSize="24"
TextWrapping="Wrap"
Text="{Binding .}"
Grid.Column="1"
Grid.Row="1"
MinHeight="55"
Cursor="Hand"
IsReadOnly="True"
FontFamily="Arial"
>
<TextBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterX="0.5" CenterY="0.5"/>
<SkewTransform CenterX="0.5" CenterY="0.5"/>
<RotateTransform CenterX="0.5" CenterY="0.5"/>
<TranslateTransform/>
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="#FF091F34" Offset="1"/>
<GradientStop Color="#FF002F5C" Offset="0.4"/>
</LinearGradientBrush>
</TextBox.Background>
</TextBox>
</Grid>
</ControlTemplate>
<Style x:Key="LostFocusStyle" TargetType="{x:Type TextBox}">
<Setter Property="Template" Value="{StaticResource LostFocusTemplate}"/>
</Style>
<ControlTemplate x:Key="GotFocusTemplate" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="55*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Width="290" TextAlignment="Left" VerticalContentAlignment="Center" BorderThickness="0" BorderBrush="Transparent"
Foreground="#FFE38E27"
FontSize="24"
TextWrapping="Wrap"
Text="{Binding .}"
Grid.Column="1"
Grid.Row="1"
MinHeight="55"
Cursor="Hand"
IsReadOnly="True"
FontFamily="Arial"
>
<TextBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.501"/>
<GradientStop Color="#FF091F34"/>
<GradientStop Color="#FF002F5C" Offset="0.5"/>
</LinearGradientBrush>
</TextBox.Background>
</TextBox>
</Grid>
</ControlTemplate>
<Style x:Key="GotFocusStyle" TargetType="{x:Type TextBox}">
<Setter Property="Template" Value="{StaticResource GotFocusTemplate}"/>
</Style>
<Style TargetType="ListBoxItem">
<EventSetter Event="GotFocus" Handler="ListItem_GotFocus"></EventSetter>
<EventSetter Event="LostFocus" Handler="ListItem_LostFocus"></EventSetter>
<EventSetter Event="Mouse.MouseMove" Handler="ListItem_MouseOver"></EventSetter>
</Style>
<DataTemplate DataType="{x:Type TextBlock}">
</DataTemplate>
<DataTemplate x:Key="CustomListData" DataType="{x:Type ListBoxItem}">
<Border BorderBrush="Black" BorderThickness="1" Margin="-2,0,0,-1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="55*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Grid.RenderTransform>
<!--<ScrollViewer x:Name="PART_ContentHost" />-->
<TextBox Width="290" TextAlignment="Left" VerticalContentAlignment="Center" BorderThickness="0" BorderBrush="Transparent"
Foreground="#FF6FB8FD"
FontSize="24"
FocusVisualStyle="{StaticResource GotFocusStyle}"
TextWrapping="Wrap"
Text="{Binding .}"
Grid.Column="1"
Grid.Row="1"
MinHeight="55"
Cursor="Hand"
IsReadOnly="True"
FontFamily="Arial"
>
<TextBox.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterX="0.5" CenterY="0.5"/>
<SkewTransform CenterX="0.5" CenterY="0.5"/>
<RotateTransform CenterX="0.5" CenterY="0.5"/>
<TranslateTransform/>
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="#FF091F34" Offset="1"/>
<GradientStop Color="#FF002F5C" Offset="0.4"/>
</LinearGradientBrush>
</TextBox.Background>
</TextBox>
</Grid>
</Border>
</DataTemplate>
<Style TargetType="{x:Type ListBox}">
<Setter Property="ItemTemplate" Value="{StaticResource CustomListData }" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
</Style>
</Window.Resources>
<Window.DataContext>
<ObjectDataProvider
ObjectType="{x:Type local:ImageLoader}"
MethodName="LoadImages"
/>
</Window.DataContext>
<ListBox ItemsSource="{Binding}" Width="320" Background="#FF021422" BorderBrush="#FF1C4B79">
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</SolidColorBrush>
</ListBox.Resources>
</ListBox>
The code behind for the mouse over event is as follows
private void ListItem_MouseOver(object sender, RoutedEventArgs e)
{
e.Handled = true;
FrameworkElement element = e.OriginalSource as FrameworkElement;
if (element != null)
{
while (VisualTreeHelper.GetParent(element) != null)
{
element = VisualTreeHelper.GetParent(element) as FrameworkElement;
TextBox item = element as TextBox;
if (item != null)
{
item.Style = (Style)item.FindResource("MouseOverFocusStyle");
return;
}
}
}
}
What am I missing? Is there an easier way to do this ?
Thanks in advance
Ryan
I think you're trying to do this the hard way, control templates support events (called triggers) see http://msdn.microsoft.com/en-us/library/ms750821%28VS.85%29.aspx
Update: Ok I think I see what your problem is, you're defining a style for type TextBox and then placing a TextBox in the style. You should still be able to combine all your styles into one by using Triggers
Example
<Style x:Key="{x:Type TextBox}" TargetType="{x:Type TextBoxBase}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="Margin" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border
Name="Border"
CornerRadius="2"
Padding="2"
Background="{DynamicResource TextBoxBackBrush}"
BorderBrush="{StaticResource SolidBorderBrush}"
BorderThickness="1" >
<ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}"/>
<Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBackgroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>

Resources