Silverlight 设置NumericUpDown的背景

Silverlight 设置NumericUpDown的背景,silverlight,xaml,Silverlight,Xaml,我有以下XAML: <toolkit:NumericUpDown Background="White"/> 但是,这不会更改控件的背景色。我已经尝试在喷丝头模板上指定背景,但这也不起作用。是否有任何方法可以使此控件具有背景而无需创建新模板?无需创建新模板?我不这么认为 这是你需要完成的吗 <toolkit1:NumericUpDown Background="Red" HorizontalAlignment="Left" VerticalAlignment="Top"&g

我有以下XAML:

<toolkit:NumericUpDown Background="White"/>


但是,这不会更改控件的背景色。我已经尝试在喷丝头模板上指定背景,但这也不起作用。是否有任何方法可以使此控件具有背景而无需创建新模板?

无需创建新模板?我不这么认为

这是你需要完成的吗

<toolkit1:NumericUpDown Background="Red" HorizontalAlignment="Left" VerticalAlignment="Top">
    <toolkit1:NumericUpDown.Resources>
        <Style x:Key="NumericUpDownStyle1" TargetType="toolkit1:NumericUpDown">
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Height" Value="22"/>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFA3AEB9" Offset="0"/>
                        <GradientStop Color="#FF8399A9" Offset="0.375"/>
                        <GradientStop Color="#FF718597" Offset="0.375"/>
                        <GradientStop Color="#FF617584" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="toolkit1:NumericUpDown">
                        <Grid Background="{TemplateBinding Background}">
                            <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>
                            <toolkit1:ButtonSpinner x:Name="Spinner" HorizontalContentAlignment="Stretch" MinWidth="35" VerticalContentAlignment="Stretch">
                                <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}">
                                    <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>
                            </toolkit1: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>
    </toolkit1:NumericUpDown.Resources>
    <toolkit1:NumericUpDown.Style>
        <StaticResource ResourceKey="NumericUpDownStyle1"/>
    </toolkit1:NumericUpDown.Style>
</toolkit1:NumericUpDown>

关键是:

<Grid Background="{TemplateBinding Background}">


如果你打算经常这样做的话,你可以把这种风格放在资源字典里。

哇,这太糟糕了。我想我将自己实现这个控件。我知道它看起来很乱,但它实际上是99%的默认模板。所有这些代码都是混合生成的,我只是更改了顶层网格背景颜色,以绑定到您在控制级别设置的颜色。