SpinnerStyle无法在Silverlight NumericUpDownControl上运行

时间:2012-08-07 14:17:17

标签: silverlight silverlight-toolkit

我在Silverlight中有一个NumericUpDown控件,我想要没有微调器。

<Style x:Key="NoSpinner" TargetType="toolkit:Spinner">
    <Setter Property="Visibility" Value="Collapsed" />
</Style>

控件:

<toolkit:NumericUpDown SpinnerStyle="{StaticResource NoSpinner}" />

但旋转器仍然显示!我这样做就像这个控件的作者suggests (link)

我知道资源正在被发现。没有给出错误,我可以应用在同一区域中定义的其他样式。

1 个答案:

答案 0 :(得分:0)

我没有Blend,如果您无法访问标准模板,则很难编辑这些控件的模板。解决方法是获取混合的预览副本并使用它来重新模板控件。

<Style TargetType="toolkit:NumericUpDown" x:Key="InputNumericUpDown">
    <Setter Property="Width" Value="111" />
    <Setter Property="Height" Value="23" />
    <Setter Property="IsTabStop" Value="False" />
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="Margin" Value="5,0,0,5"/>    
    <Setter Property="Template"><!-- This template was generated in Blend -->
        <Setter.Value>
            <ControlTemplate TargetType="toolkit:NumericUpDown">
                <Grid>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="Disabled">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="DisabledVisualElement"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="FocusStates">
                            <VisualState x:Name="Focused">
                                <Storyboard>
                                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualElement">
                                        <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                    </DoubleAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Unfocused"/>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <toolkit:ButtonSpinner x:Name="Spinner" HorizontalContentAlignment="Stretch" MinWidth="35" VerticalContentAlignment="Stretch" IsTabStop="False">
                        <TextBox x:Name="Text" AcceptsReturn="False" BorderThickness="0" Foreground="{TemplateBinding Foreground}" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" MinWidth="20" TextAlignment="Right" TextWrapping="NoWrap" Text="{TemplateBinding Value}" IsTabStop="True">
                            <TextBox.Style>
                                <Style TargetType="TextBox">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="TextBox">
                                                <ScrollViewer x:Name="ContentElement" BorderThickness="0" Padding="0"/>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </TextBox.Style>
                        </TextBox>
                    </toolkit:ButtonSpinner>
                    <Border x:Name="DisabledVisualElement" Background="#A5FFFFFF" CornerRadius="2.5,2.5,2.5,2.5" IsHitTestVisible="false" Opacity="0"/>
                    <Border x:Name="FocusVisualElement" BorderBrush="#FF45D6FA" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1,1,1,1" IsHitTestVisible="False" Opacity="0"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

模板部分是来自混合的唯一部分,但是这种样式是我用于NumericUpDowns的样式,以便将它设置为一次到达控件并一次离开的位置。