如何在XAML中创建TextBox

时间:2015-08-20 18:02:58

标签: xaml windows-10

我刚刚开始使用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成为必需的?

1 个答案:

答案 0 :(得分:0)

Thx Kristian Vukusic!在Button上设置IsEnabled="False",然后在TextBox上发生TextChanged事件时将其更改为IsEnabled="True"