0

How to apply "if conditions" on textBoxs?

Like I want to develop "GPA Calculator" application. When application starts, I want to ask a user Number of Subjects, so that only that number of textBoxes & Labels will appear that user wants.

Does "decision making" used in XAML Coding?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Khateeb321
  • 1,861
  • 23
  • 25
  • http://stackoverflow.com/questions/10463759/wp7-conditionally-show-hide-control-elements-in-data-templates – jeroenh Jun 20 '13 at 07:40

2 Answers2

1

Take the input of the textbox and use it to choose the number of textboxes and labels to appear. I dont think you need to use 'if'

Loko
  • 6,539
  • 14
  • 50
  • 78
  • @Khateeb Using the input of the textbox to tell how many labels and textboxes you want – Loko Jun 20 '13 at 10:01
0

You most probably want to use a ListBox with its elements (your text boxes and labels in needed amount) are tied to the view model via data-binding. I hope you're familiar with data binding in XAML & C#, but if not, check this out.

So, I'd create a ListBox with the ItemsSource property data-bound to an instance of ObservableCollection, containing view models for your list view.

<ListBox ItemsSource="{Binding GPAItems}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <TextBlock Text="{Binding GPAItemLabel}" />
                <TextBox Text="{Binding GPAItemText, Mode=TwoWay}" />
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

where GPAItems is ObservableCollection<GPAItem>, and GPAItem is:

class GPAItem: INotifyPropertyChanged
{
    ...
    public string GPAItemLabel {get; set;}
    public string GPAItemText {get; set;}
}

The code above is not tested (I've just written it in browser for you), but you should get the idea from here. Again, knowledge of data-binding and MVVM architecture is highly beneficial for any Windows Phone developer, so check it out, and most questions will go away.

Community
  • 1
  • 1
Haspemulator
  • 11,050
  • 9
  • 49
  • 76