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?

4

2 回答 2

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'

于 2013-06-20T07:42:53.207 回答
0

您很可能希望使用 aListBox及其元素(您的文本框和所需数量的标签)通过数据绑定绑定到视图模型。我希望您熟悉 XAML 和 C# 中的数据绑定,但如果不熟悉,请查看内容。

因此,我将创建一个ListBox属性ItemsSource数据绑定到 的实例ObservableCollection,其中包含列表视图的视图模型。

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

是,GPAItems是:ObservableCollection<GPAItem>GPAItem

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

上面的代码没有经过测试(我只是在浏览器中为你编写的),但你应该从这里得到这个想法。同样,数据绑定和 MVVM 体系结构的知识对任何 Windows Phone 开发人员都非常有益,所以检查一下,大多数问题都会消失。

于 2013-06-20T08:22:08.420 回答