MESCIUS InputMan for WPF 3.0J > InputMan for WPF の使い方 > テーマテンプレートを使用する > テーマテンプレートのカスタマイズ > Calculator.xaml |
Calculator.xaml では、ドロップダウン電卓コントロールの外観を定義します。
Calculator.xaml の内容は以下のとおりです。
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:im="clr-namespace:GrapeCity.Windows.InputMan;assembly=GrapeCity.WPF.InputMan" xmlns:imp="clr-namespace:GrapeCity.Windows.InputMan.Primitives;assembly=GrapeCity.WPF.InputMan"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Themes/Generic/Common.xaml"/> <ResourceDictionary Source="/Themes/Generic/CalculatorButton.xaml"/> </ResourceDictionary.MergedDictionaries> <im:BooleanToDoubleConverter x:Key="BooleanToDoubleConverterKey"/> <Style x:Key="GcCalculaorFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle Margin="3" StrokeThickness="1" Stroke="Black" StrokeDashArray="1 2" SnapsToDevicePixels="true"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <SolidColorBrush x:Key="GcCalculatorDisabledForegroundBrush" Color="#FFADADAD"/> <Style x:Key="CalculatorButton_StyleKey" TargetType="{x:Type imp:CalculatorButton}" BasedOn="{StaticResource {x:Type Button}}"> <Setter Property="Foreground" Value="Black"/> <Setter Property="Focusable" Value="false"/> <Setter Property="Margin" Value="2"/> <Setter Property="Padding" Value="7,4"/> <Setter Property="ContentTemplate" Value="{StaticResource CalculatorButtonContentTemplate}"/> </Style> <Style TargetType="imp:CalculatorButton" BasedOn="{StaticResource CalculatorButton_StyleKey}"/> <Style x:Key="EditButtonStyleKey" TargetType="{x:Type imp:CalculatorButton}" BasedOn="{StaticResource CalculatorButton_StyleKey}"/> <Style x:Key="ResetButtonStyleKey" TargetType="{x:Type imp:CalculatorButton}" BasedOn="{StaticResource CalculatorButton_StyleKey}"/> <Style x:Key="NumericButtonStyleKey" TargetType="{x:Type imp:CalculatorButton}" BasedOn="{StaticResource CalculatorButton_StyleKey}"/> <Style x:Key="MemoryButtonStyleKey" TargetType="{x:Type imp:CalculatorButton}" BasedOn="{StaticResource CalculatorButton_StyleKey}"> <Setter Property="Foreground" Value="Blue"/> </Style> <Style x:Key="MathButtonStyleKey" TargetType="{x:Type imp:CalculatorButton}" BasedOn="{StaticResource CalculatorButton_StyleKey}"> <Setter Property="Foreground" Value="Maroon"/> </Style> <Style x:Key="OutputStyleKey" TargetType="TextBlock" > <Setter Property="FontSize" Value="20"/> <Setter Property="Foreground" Value="Black"/> <Setter Property="TextAlignment" Value="Right"/> <Setter Property="HorizontalAlignment" Value="Right"/> <Setter Property="VerticalAlignment" Value="Bottom"/> <Setter Property="Margin" Value="0,0,4,4"/> <Setter Property="Opacity" Value="1"/> </Style> <Style x:Key="HistoryStyleKey" TargetType="TextBlock"> <Setter Property="Foreground" Value="Black"/> <Setter Property="TextAlignment" Value="Right"/> <Setter Property="HorizontalAlignment" Value="Right"/> <Setter Property="VerticalAlignment" Value="Top"/> <Setter Property="Margin" Value="0,2,2,0"/> </Style> <Style x:Key="ErrorMessageStyleKey" TargetType="TextBlock"> <Setter Property="Foreground" Value="Black"/> <Setter Property="TextAlignment" Value="Right"/> <Setter Property="HorizontalAlignment" Value="Right"/> <Setter Property="VerticalAlignment" Value="Bottom"/> <Setter Property="Margin" Value="0,0,2,2"/> <Setter Property="Opacity" Value="0"/> </Style> <Style x:Key="MemoryStatusStyleKey" TargetType="TextBlock"> <Setter Property="Foreground" Value="Black"/> <Setter Property="HorizontalAlignment" Value="Center"/> <Setter Property="VerticalAlignment" Value="Bottom"/> <Setter Property="Margin" Value="4,0,4,4"/> </Style> <ControlTemplate TargetType="{x:Type im:GcDropDownCalculator}" x:Key="GcCalculatorTemplate"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"/> <VisualState x:Name="Disabled"> <Storyboard> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="PART_DisplayBlock" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GcCalculatorDisabledForegroundBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="PART_MemoryBox" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GcCalculatorDisabledForegroundBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="PART_History" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GcCalculatorDisabledForegroundBrush}"/> </ObjectAnimationUsingKeyFrames> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="PART_ErrorBlock" Storyboard.TargetProperty="Foreground"> <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource GcCalculatorDisabledForegroundBrush}"/> </ObjectAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> <VisualStateGroup x:Name="CalculationStates"> <VisualState x:Name="Empty"/> <VisualState x:Name="HasErrors"> <Storyboard> <DoubleAnimation Duration="0" Storyboard.TargetName="PART_DisplayBlock" Storyboard.TargetProperty="Opacity" To="0"/> <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="PART_DisplayBlock" Storyboard.TargetProperty="(TextBlock.Text)" FillBehavior="HoldEnd"> <ObjectAnimationUsingKeyFrames.KeyFrames> <DiscreteObjectKeyFrame KeyTime="0" Value=""/> </ObjectAnimationUsingKeyFrames.KeyFrames> </ObjectAnimationUsingKeyFrames> <DoubleAnimation Duration="0" Storyboard.TargetName="PART_ErrorBlock" Storyboard.TargetProperty="Opacity" To="1"/> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Grid Margin="{TemplateBinding Padding}"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition /> </Grid.RowDefinitions> <Border Margin="2,2,2,3" Background="White" BorderBrush="{StaticResource EditorBorder}" BorderThickness="1" CornerRadius="2"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="auto"/> <RowDefinition Height="auto"/> </Grid.RowDefinitions> <Canvas x:Name="PART_History_Panel" Grid.ColumnSpan="2" Height="{Binding ElementName=PART_History,Path=ActualHeight}"> <Border Width="{Binding ElementName=PART_History_Panel, Path=ActualWidth}"> <TextBlock x:Name="PART_History" Text="{TemplateBinding History}" Style="{TemplateBinding HistoryStyle}" Opacity="{Binding Path=IsShowHistory, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToDoubleConverterKey}}"/> </Border> </Canvas> <TextBlock x:Name="PART_MemoryBox" Grid.Row="1" Text="M" Style="{TemplateBinding MemoryStatusStyle}" Opacity="{Binding Path=HasMemory, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BooleanToDoubleConverterKey}}"/> <TextBlock x:Name="PART_DisplayBlock" Grid.Column="1" Grid.Row="1" Text="{TemplateBinding DisplayText}" Style="{TemplateBinding OutputStyle}" /> <TextBlock x:Name="PART_ErrorBlock" Grid.Column="1" Grid.Row="1" Style="{TemplateBinding ErrorMessageStyle}" Text="{TemplateBinding DisplayText}"/> </Grid> </Border> <Grid Grid.Row="1" > <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <imp:CalculatorButton Grid.Row="0" Grid.Column="0" Content="MC" Style="{TemplateBinding MemoryButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="MemoryClear" /> <imp:CalculatorButton Grid.Row="0" Grid.Column="1" Content="MR" Style="{TemplateBinding MemoryButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="MemoryRecall" /> <imp:CalculatorButton Grid.Row="0" Grid.Column="2" Content="MS" Style="{TemplateBinding MemoryButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="MemorySave" /> <imp:CalculatorButton Grid.Row="0" Grid.Column="3" Content="M+" Style="{TemplateBinding MemoryButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="MemoryPlus" /> <imp:CalculatorButton Grid.Row="0" Grid.Column="4" Content="M-" Style="{TemplateBinding MemoryButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="MemoryMinus"/> <imp:CalculatorButton Grid.Row="1" Grid.Column="0" Content="←" Style="{TemplateBinding EditButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Backspace" /> <imp:CalculatorButton Grid.Row="1" Grid.Column="1" Content="CE" Style="{TemplateBinding ResetButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="CE" /> <imp:CalculatorButton Grid.Row="1" Grid.Column="2" Content="C" Style="{TemplateBinding ResetButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="C" /> <imp:CalculatorButton Grid.Row="1" Grid.Column="3" Content="±" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Sign" /> <imp:CalculatorButton Grid.Row="1" Grid.Column="4" Content="√" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="SquareRoot" /> <imp:CalculatorButton Grid.Row="2" Grid.Column="0" Content="7" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit7" /> <imp:CalculatorButton Grid.Row="2" Grid.Column="1" Content="8" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit8" /> <imp:CalculatorButton Grid.Row="2" Grid.Column="2" Content="9" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit9" /> <imp:CalculatorButton Grid.Row="2" Grid.Column="3" Content="/" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Divide" /> <imp:CalculatorButton Grid.Row="2" Grid.Column="4" Content="%" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Percentage" /> <imp:CalculatorButton Grid.Row="3" Grid.Column="0" Content="4" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit4" /> <imp:CalculatorButton Grid.Row="3" Grid.Column="1" Content="5" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit5" /> <imp:CalculatorButton Grid.Row="3" Grid.Column="2" Content="6" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit6" /> <imp:CalculatorButton Grid.Row="3" Grid.Column="3" Content="*" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Multiply" /> <imp:CalculatorButton Grid.Row="3" Grid.Column="4" Content="1/x" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Reciprocal" /> <imp:CalculatorButton Grid.Row="4" Grid.Column="0" Content="1" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit1" /> <imp:CalculatorButton Grid.Row="4" Grid.Column="1" Content="2" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit2" /> <imp:CalculatorButton Grid.Row="4" Grid.Column="2" Content="3" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit3" /> <imp:CalculatorButton Grid.Row="4" Grid.Column="3" Content="-" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Subtract" /> <imp:CalculatorButton Grid.Row="4" Grid.Column="4" Grid.RowSpan="2" Content="=" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Equal" /> <imp:CalculatorButton Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Content="0" Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Digit0" /> <imp:CalculatorButton Grid.Row="5" Grid.Column="2" Content="." Style="{TemplateBinding NumericButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="DecimalPoint" /> <imp:CalculatorButton Grid.Row="5" Grid.Column="3" Content="+" Style="{TemplateBinding MathButtonStyle}" Command="{x:Static im:GcDropDownCalculator.ProcessCommand}" CommandParameter="Add" /> </Grid> </Grid> </Border> </ControlTemplate> <Style TargetType="{x:Type im:GcDropDownCalculator}" x:Key="GcDropDownCalculator_StyleKey"> <Setter Property="FocusVisualStyle" Value="{StaticResource GcCalculaorFocusVisual}"/> <Setter Property="BorderBrush" Value="{StaticResource ListBoxBorderBrush}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> <Setter Property="Padding" Value="6"/> <Setter Property="Template" Value="{StaticResource GcCalculatorTemplate}"/> <Setter Property="EditButtonStyle" Value="{StaticResource EditButtonStyleKey}"/> <Setter Property="MathButtonStyle" Value="{StaticResource MathButtonStyleKey}"/> <Setter Property="MemoryButtonStyle" Value="{StaticResource MemoryButtonStyleKey}"/> <Setter Property="NumericButtonStyle" Value="{StaticResource NumericButtonStyleKey}"/> <Setter Property="ResetButtonStyle" Value="{StaticResource ResetButtonStyleKey}"/> <Setter Property="MemoryStatusStyle" Value="{StaticResource MemoryStatusStyleKey}"/> <Setter Property="OutputStyle" Value="{StaticResource OutputStyleKey}"/> <Setter Property="HistoryStyle" Value="{StaticResource HistoryStyleKey}"/> <Setter Property="ErrorMessageStyle" Value="{StaticResource ErrorMessageStyleKey}"/> </Style> <Style TargetType="im:GcDropDownCalculator" BasedOn="{StaticResource GcDropDownCalculator_StyleKey}"/> </ResourceDictionary>