Created
November 23, 2019 11:51
-
-
Save Ganeshcse/dbdbf33b6996ef26bd4589472fffd7c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Style TargetType="{x:Type local:StagedProgressBar}"> | |
<Setter Property="BorderBrush" Value="Black"></Setter> | |
<Setter Property="BorderThickness" Value="1"></Setter> | |
<Setter Property="Foreground" Value="Black"></Setter> | |
<Setter Property="Background" Value="#e6e6e6"></Setter> | |
<Setter Property="Border.CornerRadius" Value="5"></Setter> | |
<Setter Property="HorizontalContentAlignment" Value="Center"></Setter> | |
<Setter Property="VerticalContentAlignment" Value="Center"></Setter> | |
<Setter Property="Template"> | |
<Setter.Value> | |
<ControlTemplate TargetType="{x:Type local:StagedProgressBar}"> | |
<Grid> | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition Width="50" /> | |
<ColumnDefinition Width="20" /> | |
</Grid.ColumnDefinitions> | |
<Border x:Name="StageBorder" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" | |
Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" CornerRadius="{TemplateBinding Border.CornerRadius}"> | |
<TextBlock x:Name="StageTextBlock" Text="{TemplateBinding StageName}" FontFamily="Segoe UI" FontSize="12" | |
Foreground="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center"/> | |
</Border> | |
<Rectangle x:Name="StageRectangle" Height="2" Grid.Column="1" Fill="{TemplateBinding Background}" | |
Visibility="{Binding RelativeSource={RelativeSource AncestorType=local:StagedProgressBar, Mode=FindAncestor}, Path=IsRectangleVisible, | |
Converter={StaticResource BooleanToVisibilityConverter}}"/> | |
</Grid> | |
<ControlTemplate.Triggers> | |
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:StagedProgressBar}, Path=InProgress}" Value="True"> | |
<Setter TargetName="StageBorder" Property="Background" Value="Green"/> | |
<Setter TargetName="StageTextBlock" Property="Foreground" Value="White"/> | |
<Setter TargetName="StageRectangle" Property="Fill" Value="Green"/> | |
</DataTrigger> | |
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:StagedProgressBar}, Path=IsCompleted}" Value="True"> | |
<Setter TargetName="StageBorder" Property="Background" Value="Red"/> | |
<Setter TargetName="StageTextBlock" Property="Foreground" Value="White"/> | |
<Setter TargetName="StageRectangle" Property="Fill" Value="Red"/> | |
</DataTrigger> | |
</ControlTemplate.Triggers> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
</Style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<DataTemplate x:Key="StagedProgressDataTemplate" DataType="local:StagedProgress"> | |
<Grid> | |
<local:StagedProgressBar | |
StageName="{Binding StageName}" | |
Value="{Binding ProgressValue, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" | |
IsCompleted="{Binding IsCompleted, UpdateSourceTrigger=PropertyChanged}" | |
InProgress="{Binding InProgress, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" | |
IsRectangleVisible="{Binding IsRectangleVisible, UpdateSourceTrigger=PropertyChanged}" | |
Height="30"/> | |
</Grid> | |
</DataTemplate> | |
<StackPanel Orientation="Horizontal" Grid.Row="0" > | |
<Button Content="Make Progress" Height="30" Width="100" Click="ButtonBase1_OnClick" Margin="10,0,0,0"/> | |
</StackPanel> | |
<ItemsControl Grid.Row="6" ItemTemplate="{StaticResource StagedProgressDataTemplate}" x:Name="StagedProgressBarItemsControl"> | |
<ItemsControl.ItemsPanel> | |
<ItemsPanelTemplate> | |
<StackPanel Orientation="Horizontal" IsItemsHost="True" /> | |
</ItemsPanelTemplate> | |
</ItemsControl.ItemsPanel> | |
</ItemsControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private readonly ObservableCollection<StagedProgress> _stagedProgressList; | |
private void ButtonBase1_OnClick(object sender, RoutedEventArgs e) | |
{ | |
var firstNotStartedItem = _stagedProgressList.FirstOrDefault(x => !x.InProgress && !x.IsCompleted); | |
if (firstNotStartedItem != null) | |
{ | |
var firstNotStartedItemIndex = _stagedProgressList.IndexOf(firstNotStartedItem); | |
firstNotStartedItem.ProgressValue = 100; | |
firstNotStartedItem.InProgress = true; | |
_stagedProgressList[firstNotStartedItemIndex] = firstNotStartedItem; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StagedProgress | |
{ | |
public int ProgressValue { get; set; } | |
public string StageName { get; set; } | |
public bool InProgress { get; set; } | |
public bool IsCompleted { get; set; } | |
public bool IsRectangleVisible { get; set; } | |
public StagedProgress() | |
{ | |
IsRectangleVisible = true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StagedProgressBar : ProgressBar | |
{ | |
static StagedProgressBar() | |
{ | |
DefaultStyleKeyProperty.OverrideMetadata(typeof(StagedProgressBar), new FrameworkPropertyMetadata(typeof(StagedProgressBar))); | |
} | |
public string StageName | |
{ | |
get { return (string)GetValue(StageNameProperty); } | |
set { SetValue(StageNameProperty, value); } | |
} | |
// Using a DependencyProperty as the backing store for StageName. This enables animation, styling, binding, etc... | |
public static readonly DependencyProperty StageNameProperty = | |
DependencyProperty.Register("StageName", typeof(string), typeof(StagedProgressBar), new PropertyMetadata(string.Empty)); | |
public bool InProgress | |
{ | |
get { return (bool)GetValue(InProgressProperty); } | |
set { SetValue(InProgressProperty, value); } | |
} | |
public bool IsCompleted | |
{ | |
get { return (bool)GetValue(IsCompletedProperty); } | |
set { SetValue(IsCompletedProperty, value); } | |
} | |
public bool IsRectangleVisible | |
{ | |
get { return (bool)GetValue(IsRectangleVisibleProperty); } | |
set { SetValue(IsRectangleVisibleProperty, value); } | |
} | |
// Using a DependencyProperty as the backing store for IsRectangleVisible. This enables animation, styling, binding, etc... | |
public static readonly DependencyProperty IsRectangleVisibleProperty = | |
DependencyProperty.Register("IsRectangleVisible", typeof(bool), typeof(StagedProgressBar), new PropertyMetadata(false)); | |
// Using a DependencyProperty as the backing store for IsCompleted. This enables animation, styling, binding, etc... | |
public static readonly DependencyProperty IsCompletedProperty = | |
DependencyProperty.Register("IsCompleted", typeof(bool), typeof(StagedProgressBar), new PropertyMetadata(false)); | |
// Using a DependencyProperty as the backing store for InProgress. This enables animation, styling, binding, etc... | |
public static readonly DependencyProperty InProgressProperty = | |
DependencyProperty.Register("InProgress", typeof(bool), typeof(StagedProgressBar), new PropertyMetadata(false)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment