Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
XamNumericInput - Override default style
posted

Hi,

Im currently trying to achieve that the XamNumericInput has the same style as the rest of my textboxes. So i thought just copy the style and change the TargetType to XamNumericInput. But somehow i am ending up with a textbox i cannot interact with and not showing its value. What im doing wrong here?

Here is my xaml:

<Style x:Key="XamNumericInputStyle"
               TargetType="{x:Type ig:XamNumericInput}">
            <Setter Property="Background"
                    Value="{StaticResource ControlDarkBrush}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ig:XamNumericInput">
                        <Border Name="Border"
                                Padding="2"
                                Background="{TemplateBinding Property=Background}"
                                BorderBrush="{StaticResource BorderMediumBrush}"
                                BorderThickness="1"
                                CornerRadius="2">
                            <ScrollViewer Name="PART_ContentHost" />
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsReadOnly" Value="True">
                                <Setter TargetName="Border"
                                        Property="Focusable"
                                        Value="False" />
                                <Setter TargetName="Border"
                                        Property="Background"
                                        Value="{StaticResource DisabledControlDarkBrush}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter TargetName="Border"
                                        Property="Focusable"
                                        Value="False" />
                                <Setter TargetName="Border"
                                        Property="Background"
                                        Value="{StaticResource DisabledControlDarkBrush}" />
                            </Trigger>
                            <Trigger Property="IsFocused" Value="True">
                                <Setter TargetName="Border"
                                        Property="Background"
                                        Value="{StaticResource ControlSelectedFocusedBrush}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Margin"
                    Value="4,4,4,4" />
            <Setter Property="HorizontalAlignment"
                    Value="Stretch" />
            <Setter Property="MaxHeight"
                    Value="27" />
            <Setter Property="MinWidth"
                    Value="100" />
        </Style>

Parents
No Data
Reply
  • 28690
    Verified Answer
    Offline posted

    Hello Elias,

    I have been investigating the code that you have provided, and it appears that the reason you are seeing a problematic behavior is that you have effectively replaced the default template of the XamNumericInput with the template of a TextBox. The underlying control is still a XamNumericInput though, so it is essentially missing any internal code of TextBox. I would very highly recommend against this. If you were to continue with this, I would simply recommend using a TextBox instead of the XamNumericInput as you are missing key pieces of the XamNumericInput’s template that contribute to the functionality of that control.

    If you are looking to modify the default template of the XamNumericInput to look like your TextBox controls within your project, I would instead recommend including the default style for XamNumericInput and making your changes there. You can find this default template in the generic.shared.xaml file commonly found at the following directory when the Infragistics for WPF product is installed:

    C:\Program Files (x86)\Infragistics\<your version here>\WPF\DefaultStyles\MaskInput\generic.shared.xaml

    Please let me know if you have any other questions or concerns on this matter.

Children
No Data