ProgressBar를 처음 써보면서 배터리 모양으로 만들어 보려했는데
아직 배운지 얼마 안되서 어떻게 해야할지 감이 안 잡힙니다…
ProgressBar의 기본 템플릿을 수정해서 배터리 느낌을 만들고 싶었는데
모양만 그럴싸하게 만들다보니깐 배터리 느낌을 Border로 나누다보니 스타일에서 width값을 바꾸면 또 깨지고 그러네요…
혹시 어떻게 만들어야할지 조언좀 주실 수 있나요
그리고 혹시 ProgressBar 끝에 건전지 처럼 볼록한 느낌을 넣고싶은데
방법이 있다면 알고싶습니다.
<Style x:Key="ProgressBarStyle1Battery" TargetType="{x:Type ProgressBar}">
<Setter Property="Foreground" Value="{StaticResource ProgressBar.Progress}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource ProgressBar.Border}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid x:Name="TemplateRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Determinate"/>
<VisualState x:Name="Indeterminate">
<Storyboard RepeatBehavior="Forever">
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<EasingDoubleKeyFrame KeyTime="0" Value="0.25"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0.25"/>
<EasingDoubleKeyFrame KeyTime="0:0:2" Value="0.25"/>
</DoubleAnimationUsingKeyFrames>
<PointAnimationUsingKeyFrames Storyboard.TargetName="Animation" Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)">
<EasingPointKeyFrame KeyTime="0" Value="-0.5,0.5"/>
<EasingPointKeyFrame KeyTime="0:0:1" Value="0.5,0.5"/>
<EasingPointKeyFrame KeyTime="0:0:2" Value="1.5,0.5"/>
</PointAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1"/>
<Rectangle x:Name="PART_Track"/>
<Grid x:Name="PART_Indicator" ClipToBounds="true" HorizontalAlignment="Left">
<Border Background="{StaticResource ProgressBar.Progress}" BorderBrush="{StaticResource ProgressBar.Progress}" BorderThickness="0" CornerRadius="0.3" Margin="1,1,0,1"/>
</Grid>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Border Padding="0" BorderBrush="White" BorderThickness="1" Width="15" Height="15" CornerRadius="1,0,0,1" Margin="0,0,0,0" Grid.Column="0"/>
<Border Padding="0" BorderBrush="White" BorderThickness="1" Width="15" Height="15" CornerRadius="0.0" Margin="-1,0,0,0" Grid.Column="1"/>
<Border Padding="0" BorderBrush="White" BorderThickness="1" Width="16" Height="15" CornerRadius="0,0,0,0" Margin="-1,0,0,0" Grid.Column="2"/>
<Border Padding="0" BorderBrush="White" BorderThickness="1" Width="16" Height="15" CornerRadius="0,1,1,0" Margin="-1,0,0,0" Grid.Column="3"/>
</Grid>
<Grid>
<Border Background="White" Width="4" Height="7" BorderBrush="White" BorderThickness="1" CornerRadius="0,1,1,0" Margin="50,0,0,0"/>
</Grid>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="Orientation" Value="Vertical">
<Setter Property="LayoutTransform" TargetName="TemplateRoot">
<Setter.Value>
<RotateTransform Angle="-90"/>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
제가 사용한 기본 템플릿 입니다.
width 60 height 15로할땐 그나마 비슷하게 나오긴 하는데 크기를 바꾸면 다 깨지네요…
대충 이런 모양으로 만들고 싶습니다.