locked
Unable to Use Binding.ValidationRule

    Question

  • Hi, 

    I am trying to restrict a textbox field to numbers only. I have followed the binding tutorial and I have this code: 

    <TextBox x:Name="CaseNumberEntry" HorizontalAlignment="Left" Margin="248,166,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="0.524,0.519" PlaceholderText="Case Number..." BorderBrush="{StaticResource BorderBrushAll}" Height="37" Width="458" FontSize="{StaticResource DefaultFontSize}" InputScope="Number">
                <TextBox.Foreground>
                    <SolidColorBrush Color="Black"/>
                </TextBox.Foreground>
                <TextBox.Text>
                    <Binding Path="CaseNumber" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRule>
                            <ExceptionValidationRule />
                        </Binding.ValidationRule>
                    </Binding>
                </TextBox.Text>
            </TextBox>

    The problem is that I get an error that states: "The member ValidationRule is not recognized or it not accesssible." I'm trying to follow the Microsoft guide. What am I doing wrong? 

    Thanks.

    Thursday, June 26, 2014 6:56 PM

Answers

  • Hi,

    The following example demonstrates binding a ComboBox to a collection of FontFamily objects:

     <ComboBox x:Name="FontsCombo" Height="20" Width="150" ItemsSource="{Binding}" />

    public Page() { InitializeComponent(); ObservableCollection<FontFamily> fonts = new ObservableCollection<FontFamily>(); fonts.Add(new FontFamily("Arial")); fonts.Add(new FontFamily("Courier New")); fonts.Add(new FontFamily("Times New Roman")); FontsCombo.DataContext = fonts; }

    And I recommend you can see some links below:

     Data binding to controls

    Data binding with XAML

    XAML data binding sample

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, June 27, 2014 1:38 AM

All replies

  • You probably followed a WPF tutorial. Unfortunately the ValidationRule property does not exist in the WinRT Binding class. You have to look for a non-standard alternative, like one of the suggestions over here, or a third-party control suite.

    Thursday, June 26, 2014 7:33 PM
  • Awesome. How would I go about binding an enumerable list to a combobox? I have literally looked everywhere and nothing seems to be working. 

    I'm honestly so lost because I've read so many articles stating so many different things, any ideas you've got would be helpful.

    Thursday, June 26, 2014 7:49 PM
  • Hi,

    The following example demonstrates binding a ComboBox to a collection of FontFamily objects:

     <ComboBox x:Name="FontsCombo" Height="20" Width="150" ItemsSource="{Binding}" />

    public Page() { InitializeComponent(); ObservableCollection<FontFamily> fonts = new ObservableCollection<FontFamily>(); fonts.Add(new FontFamily("Arial")); fonts.Add(new FontFamily("Courier New")); fonts.Add(new FontFamily("Times New Roman")); FontsCombo.DataContext = fonts; }

    And I recommend you can see some links below:

     Data binding to controls

    Data binding with XAML

    XAML data binding sample

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, June 27, 2014 1:38 AM