Created
November 27, 2019 17:42
-
-
Save Ganeshcse/c62e5657fd730b67ac62b2c1a5493137 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
public class BarControl | |
{ | |
public Brush BarBrush { get; set; } | |
public double BarHeight { get; set; } | |
public int BarValue { get; set; } | |
public double BarWidth { get; set; } | |
public bool IsBarOnDownSide => BarValue <= 0; | |
public double MaxBarControlHeight { get; set; } | |
} |
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
<Window.Resources> | |
<DataTemplate x:Key="BarControlDataTemplate" DataType="local:BarControl"> | |
<Grid Height="{Binding MaxBarControlHeight}"> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="{Binding MaxBarControlHeight}"/> | |
<RowDefinition Height="4"/> | |
<RowDefinition Height="{Binding MaxBarControlHeight}"/> | |
</Grid.RowDefinitions> | |
<Border x:Name="TopBorder" Grid.Row="0" Height="{Binding MaxBarControlHeight}" Width="{Binding BarWidth}" BorderBrush="Black" BorderThickness="0" | |
ToolTip="{Binding BarValue}"> | |
<Rectangle Fill="{Binding BarBrush}" Height="{Binding BarHeight}" Width="{Binding BarWidth}" VerticalAlignment="Bottom" | |
Stroke="White" StrokeThickness="1"/> | |
</Border> | |
<Rectangle Grid.Row="1" Height="4" Fill="Yellow" Stroke="Black" StrokeThickness="1" /> | |
<Border x:Name="BottomBorder" Grid.Row="2" Height="{Binding MaxBarControlHeight}" Width="{Binding BarWidth}" BorderBrush="Black" BorderThickness="0" | |
ToolTip="{Binding BarValue}"> | |
<Rectangle Fill="{Binding BarBrush}" Height="{Binding BarHeight}" Width="{Binding BarWidth}" VerticalAlignment="Top" | |
Stroke="White" StrokeThickness="1"/> | |
</Border> | |
</Grid> | |
<DataTemplate.Triggers> | |
<DataTrigger Binding="{Binding IsBarOnDownSide}" Value="True"> | |
<Setter TargetName="BottomBorder" Property="Visibility" Value="Visible" /> | |
<Setter TargetName="TopBorder" Property="Visibility" Value="Collapsed" /> | |
</DataTrigger> | |
<DataTrigger Binding="{Binding IsBarOnDownSide}" Value="False"> | |
<Setter TargetName="BottomBorder" Property="Visibility" Value="Collapsed" /> | |
<Setter TargetName="TopBorder" Property="Visibility" Value="Visible" /> | |
</DataTrigger> | |
</DataTemplate.Triggers> | |
</DataTemplate> | |
</Window.Resources> | |
<Grid Margin="10"> | |
<ItemsControl ItemTemplate="{StaticResource BarControlDataTemplate}" x:Name="BarItemsControl"> | |
<ItemsControl.ItemsPanel> | |
<ItemsPanelTemplate> | |
<StackPanel Orientation="Horizontal" IsItemsHost="True" /> | |
</ItemsPanelTemplate> | |
</ItemsControl.ItemsPanel> | |
</ItemsControl> | |
</Grid> |
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 MainWindow() | |
{ | |
InitializeComponent(); | |
_barControls = new ObservableCollection<BarControl>(); | |
LoadData(); | |
} | |
private void LoadData() | |
{ | |
var barControl = new BarControl | |
{ | |
BarBrush = new SolidColorBrush(Color.FromRgb(128, 128, 128)), | |
BarValue = 40, | |
BarHeight = Math.Abs(50), | |
BarWidth = 50 | |
}; | |
_barControls.Add(barControl); | |
barControl = new BarControl | |
{ | |
BarBrush = new SolidColorBrush(Color.FromRgb(128, 128, 128)), | |
BarValue = 80, | |
BarHeight = Math.Abs(80), | |
BarWidth = 50 | |
}; | |
_barControls.Add(barControl); | |
barControl = new BarControl | |
{ | |
BarBrush = new SolidColorBrush(Color.FromRgb(128, 128, 128)), | |
BarValue = 100, | |
BarHeight = Math.Abs(100), | |
BarWidth = 50 | |
}; | |
_barControls.Add(barControl); | |
barControl = new BarControl | |
{ | |
BarBrush = new SolidColorBrush(Color.FromRgb(128, 128, 128)), | |
BarValue = 120, | |
BarHeight = Math.Abs(120), | |
BarWidth = 50 | |
}; | |
_barControls.Add(barControl); | |
barControl = new BarControl | |
{ | |
BarBrush = new SolidColorBrush(Color.FromRgb(128, 128, 128)), | |
BarValue = 160, | |
BarHeight = Math.Abs(160), | |
BarWidth = 50 | |
}; | |
_barControls.Add(barControl); | |
barControl = new BarControl | |
{ | |
BarBrush = new SolidColorBrush(Color.FromRgb(128, 128, 128)), | |
BarValue = -50, | |
BarHeight = Math.Abs(-50), | |
BarWidth = 50 | |
}; | |
_barControls.Add(barControl); | |
barControl = new BarControl | |
{ | |
BarBrush = new SolidColorBrush(Color.FromRgb(128, 128, 128)), | |
BarValue = -30, | |
BarHeight = Math.Abs(-30), | |
BarWidth = 50 | |
}; | |
_barControls.Add(barControl); | |
var maxBarHeight = _barControls.Max(x => x.BarHeight); | |
_barControls.ToList().ForEach(x => x.MaxBarControlHeight = maxBarHeight); | |
BarItemsControl.ItemsSource = _barControls; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment