crazyPixel
crazyPixel

Reputation: 2330

Limit IntegerUpDown to a specific set of numbers on WPF

I am new to WPF, and there is something I need to do but just couldnt find no where how to do it (I do know it should be possible since there is a similar object on C# forms) I want to limit the dataset of IntegerUpDown on a wpf form s.t the default value will be 1 up to 64 as powers of two, problem is there is no place (by my google search and the microsoft website) that tells me how to do that, any help?

I think ill go with the combobox but do you have any clue why it might not recognize the style? (its on the same file...) im adding the combobox as is -

    <xctk:ComboBox Canvas.Left="334" Canvas.Top="80" FormatString="" 
        Maximum="64" Minimum="2" Name="integerUpDownFrameAvg" Style="{StaticResource myComboBoxStyle}" 
        Text="0" Value="0" Width="60" DataContext="{Binding}">
        <ComboBoxItem Content="1"></ComboBoxItem>
        <ComboBoxItem Content="2"></ComboBoxItem>
        <ComboBoxItem Content="4"></ComboBoxItem>
        <ComboBoxItem Content="8"></ComboBoxItem>
        <ComboBoxItem Content="16"></ComboBoxItem>
        <ComboBoxItem Content="32"></ComboBoxItem>
        <ComboBoxItem Content="64"></ComboBoxItem>
    </xctk:ComboBox>

that is the style -

<Style x:Key="myComboBoxStyle"
   TargetType="xctk:ComboBox">
    <Setter Property="FontSize"
      Value="12" />
    <Setter Property="Foreground"
      Value="White" />
    <Setter Property="BorderThickness"
      Value="1" />
    <Setter Property="Background"
      Value="#FF4A4A3C" />
    <Setter Property="BorderBrush"
      Value="Black" />
    <Setter Property="Width"
      Value="60" />
    <Setter Property="Height"
      Value="20" />

and I included the -

xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"

on the header, it dosent work though the error is missing an assembly...

Upvotes: 0

Views: 1326

Answers (1)

ProgramFOX
ProgramFOX

Reputation: 6390

Then why don't you use a ComboBox:

<ComboBox Name="intComboBox">  
    <ComboBoxItem Content="1"></ComboBoxItem>
    <ComboBoxItem Content="2"></ComboBoxItem>
    <ComboBoxItem Content="4"></ComboBoxItem>
    <ComboBoxItem Content="8"></ComboBoxItem>
    <ComboBoxItem Content="16"></ComboBoxItem>
    <ComboBoxItem Content="32"></ComboBoxItem>
    <ComboBoxItem Content="64"></ComboBoxItem>
</ComboBox>

Upvotes: 2

Related Questions