如何使 XAML 中需要 TextBox
How to make TextBox required in XAML
我刚开始为 Windows 10 平台开发,我不知道如何制作 XAML 中所需的文本框,因此不可能保存数据而不添加一段文字。
这是我的 .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 成为必填项吗?
谢谢Kristian Vukusic!在 Button 上设置 IsEnabled="False"
,然后在 TextBox 上发生 TextChanged 事件时将其更改为 IsEnabled="True"
效果很好。
我刚开始为 Windows 10 平台开发,我不知道如何制作 XAML 中所需的文本框,因此不可能保存数据而不添加一段文字。
这是我的 .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 成为必填项吗?
谢谢Kristian Vukusic!在 Button 上设置 IsEnabled="False"
,然后在 TextBox 上发生 TextChanged 事件时将其更改为 IsEnabled="True"
效果很好。