Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal class ButtonAnalysisControl : Control
- {
- static ButtonAnalysisControl()
- {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(ButtonAnalysisControl), new FrameworkPropertyMetadata(typeof(ButtonAnalysisControl)));
- }
- public string Text
- {
- get { return (string)GetValue(TextProperty); }
- set { SetValue(TextProperty, value); }
- }
- public Brush BackgroundBrush
- {
- get { return (Brush)GetValue(BackgroundBrushProperty); }
- set { SetValue(BackgroundBrushProperty, value); }
- }
- public ObservableCollection<ViewCommand> ChildCommands
- {
- get { return (ObservableCollection<ViewCommand>)GetValue(ChildCommandsProperty); }
- set { SetValue(ChildCommandsProperty, value); }
- }
- public static readonly DependencyProperty TextProperty =
- DependencyProperty.Register("Text", typeof(string), typeof(ButtonAnalysisControl), new UIPropertyMetadata(string.Empty));
- public static readonly DependencyProperty BackgroundBrushProperty =
- DependencyProperty.Register("BackgroundBrush", typeof(Brush), typeof(ButtonAnalysisControl), new UIPropertyMetadata(Brushes.Transparent));
- public static readonly DependencyProperty ChildCommandsProperty =
- DependencyProperty.Register("ChildCommands", typeof(ObservableCollection<ViewCommand>), typeof(ButtonAnalysisControl), new UIPropertyMetadata(null));
- }
- <Style TargetType="anal:ButtonAnalysisControl">
- <Style.Triggers>
- <EventTrigger RoutedEvent="MouseDown">
- <EventTrigger.Actions>
- <BeginStoryboard>
- <Storyboard>
- <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="ContextMenu.IsOpen">
- <DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
- </BooleanAnimationUsingKeyFrames>
- </Storyboard>
- </BeginStoryboard>
- </EventTrigger.Actions>
- </EventTrigger>
- </Style.Triggers>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="anal:ButtonAnalysisControl">
- <Grid>
- <Grid.RowDefinitions>
- <RowDefinition Height="Auto" />
- <RowDefinition Height="*"/>
- </Grid.RowDefinitions>
- <Grid.ColumnDefinitions>
- <ColumnDefinition Width="*" />
- </Grid.ColumnDefinitions>
- <TextBlock TextAlignment="Center"
- VerticalAlignment="Stretch"
- Foreground="{StaticResource CommandBarForeground}"
- Background="{StaticResource MainForegroundBrush}"
- FontFamily="{StaticResource FontFamily}"
- FontSize="10"
- Grid.Column="0"
- Grid.Row="0">
- <TextBlock.Text>
- <Binding Path="Text" StringFormat="{}{0}%" RelativeSource="{RelativeSource TemplatedParent}" />
- </TextBlock.Text>
- </TextBlock>
- <Rectangle Grid.Column="0"
- Grid.Row="1">
- <Rectangle.Fill>
- <Binding Path="BackgroundBrush" RelativeSource="{RelativeSource TemplatedParent}" />
- </Rectangle.Fill>
- </Rectangle>
- </Grid>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- <Setter Property="ContextMenu">
- <Setter.Value>
- <ContextMenu>
- <ContextMenu.ItemsSource>
- <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ChildCommands"/>
- </ContextMenu.ItemsSource>
- <ContextMenu.ItemContainerStyle>
- <Style TargetType="{x:Type MenuItem}">
- <Setter Property="MenuItem.Header" Value="{Binding Command.Text}"/>
- </Style>
- </ContextMenu.ItemContainerStyle>
- </ContextMenu>
- </Setter.Value>
- </Setter>
- </Style>
- public ButtonAnalysisAdorner(UIElement adornedElement, int numberOfTimesFieldFilled, int numberOfLoggedViews, ObservableCollection<ViewCommand> childCommands)
- : base(adornedElement)
- {
- _visuals = new VisualCollection(this);
- _contentPresenter = new ContentPresenter();
- ButtonAnalysisControl bac = new ButtonAnalysisControl();
- bac.Text = percentage.ToString(CultureInfo.InvariantCulture);
- bac.BackgroundBrush = PercentColorRanges.GetColorFromPercentage((int)percentage, 0.75);
- bac.ToolTip = ToolTipValue(numberOfTimesFieldFilled, numberOfLoggedViews);
- bac.ChildCommands = childCommands;
- Content = bac;
- _visuals.Add(_contentPresenter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement