【发布时间】:2015-08-21 02:53:43
【问题描述】:
我刚开始开发 Windows 10 平台,但我不知道如何制作 XAML 中所需的 TextBox,因此无法在不添加文本的情况下保存数据。
这是我的 .xaml 文件:
<Page
x:Class="SessionTracker.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SessionTracker"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<TextBox x:Name="nameInput" HorizontalAlignment="Left" Height="15" Margin="20,29,0,0" PlaceholderText="Spot Name" VerticalAlignment="Top" Width="150"/>
<DatePicker x:Name="sessionDate" HorizontalAlignment="Left" Height="38" Margin="20,94,0,0" VerticalAlignment="Top" Width="150" d:LayoutOverrides="HorizontalAlignment" />
<Button x:Name="saveButton" FontSize="12" Content="save" Height="30" Margin="20,144,0,0" VerticalAlignment="Top" Width="75" Click="Button_SaveSession"/>
</Grid>
</Page>
有什么方法可以使 TextBox 成为必需的吗?
【问题讨论】:
-
“必需”是什么意思?总是在您的页面中包含 DatePicker 或其他内容?
-
表示不加Date就无法保存数据。
-
您最初可以在按钮上设置
IsEnabled=False,当您通过DatePicker选择日期(SelectionChanged)时,将IsEnabled设置回true。 -
谢谢!这就是我一直在寻找的。但我认识到 DatePicker 始终设置,所以我在 nameInput TextBox 上使用了 TextChanged 事件。
标签: xaml windows-10