如何设置默认选择的字段

发布于 2024-10-08 07:59:33 字数 3301 浏览 1 评论 0原文

你好,我不知道如何设置默认选择的字段 这是我的代码:

<DockPanel>
        <Grid DockPanel.Dock="Left" Height="426">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="63"/>
                <RowDefinition Height="79"/>
            </Grid.RowDefinitions>
            <Label Foreground="blue" Margin="0,1,0,4" Height="26">Message Number:</Label>
            <Label Grid.Row="1" Foreground="blue" Margin="0 10 0 0">Title:</Label>
            <Label Grid.Row="2" Foreground="blue" >Message Date:</Label>
            <Label Grid.Row="3" Foreground="blue" Margin="0 10 0 0">Contact Mail:</Label>
            <Label Grid.Row="4" Foreground="blue" Margin="0 10 0 0">Message Type:</Label>
            <Label Grid.Row="5" Foreground="blue" Margin="0 10 0 0">Message Details:</Label>
            <Button Grid.Row="6" Name="saveBtn" Background="White" Margin="6,20,11,36" Width="89" Click="saveBtn_Click">Save</Button>
            <TextBox Grid.Column="1" Name="IDtbx" Margin="0 10 0 0"></TextBox>
            <TextBox Grid.Row="1" Grid.Column="1" Name="titletbx" Margin="0 10 0 0"></TextBox>
            <Calendar Grid.Row="2" Grid.Column="1" Name="calender"></Calendar>
            <TextBox Grid.Row="3" Grid.Column="1" Name="mailtbx" Margin="0 10 0 0"></TextBox>
            <ComboBox Grid.Row="4" Grid.Column="1" Name="typecbx" Margin="0 10 0 0"></ComboBox>
            <TextBox Grid.Row="5" Grid.Column="1" Name="detailstbx" Margin="0,10,0,1" TextWrapping="Wrap" AcceptsReturn="True"></TextBox>
        </Grid>
        <DockPanel>
            <Grid DockPanel.Dock="Left" Height="406">
                <Grid.RowDefinitions>
                    <RowDefinition Height="372"></RowDefinition>

                    <RowDefinition Height="7"/>
                    <RowDefinition Height="27*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Border CornerRadius="6" BorderBrush="Purple" BorderThickness="3" Margin="18,8,0,7" Grid.RowSpan="2" Width="182">
                    <Image Grid.Row="1" Name="messageImage" Height="359" Width="177"></Image>
                </Border>
                <Button Name="ChangeImagebtn" Background="white" Content="Change Image" Grid.Row="2" Margin="21,2,0,-2" Click="ChangeImagebtn_Click"></Button>
            </Grid>
        </DockPanel>

    </DockPanel>

当我运行程序时,由于某种原因,保存按钮被选中,但我不希望它被选中。 预先感谢您的帮助

hello i dont know how how to set a field to be selected by default
this is my code:

<DockPanel>
        <Grid DockPanel.Dock="Left" Height="426">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="63"/>
                <RowDefinition Height="79"/>
            </Grid.RowDefinitions>
            <Label Foreground="blue" Margin="0,1,0,4" Height="26">Message Number:</Label>
            <Label Grid.Row="1" Foreground="blue" Margin="0 10 0 0">Title:</Label>
            <Label Grid.Row="2" Foreground="blue" >Message Date:</Label>
            <Label Grid.Row="3" Foreground="blue" Margin="0 10 0 0">Contact Mail:</Label>
            <Label Grid.Row="4" Foreground="blue" Margin="0 10 0 0">Message Type:</Label>
            <Label Grid.Row="5" Foreground="blue" Margin="0 10 0 0">Message Details:</Label>
            <Button Grid.Row="6" Name="saveBtn" Background="White" Margin="6,20,11,36" Width="89" Click="saveBtn_Click">Save</Button>
            <TextBox Grid.Column="1" Name="IDtbx" Margin="0 10 0 0"></TextBox>
            <TextBox Grid.Row="1" Grid.Column="1" Name="titletbx" Margin="0 10 0 0"></TextBox>
            <Calendar Grid.Row="2" Grid.Column="1" Name="calender"></Calendar>
            <TextBox Grid.Row="3" Grid.Column="1" Name="mailtbx" Margin="0 10 0 0"></TextBox>
            <ComboBox Grid.Row="4" Grid.Column="1" Name="typecbx" Margin="0 10 0 0"></ComboBox>
            <TextBox Grid.Row="5" Grid.Column="1" Name="detailstbx" Margin="0,10,0,1" TextWrapping="Wrap" AcceptsReturn="True"></TextBox>
        </Grid>
        <DockPanel>
            <Grid DockPanel.Dock="Left" Height="406">
                <Grid.RowDefinitions>
                    <RowDefinition Height="372"></RowDefinition>

                    <RowDefinition Height="7"/>
                    <RowDefinition Height="27*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="200"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Border CornerRadius="6" BorderBrush="Purple" BorderThickness="3" Margin="18,8,0,7" Grid.RowSpan="2" Width="182">
                    <Image Grid.Row="1" Name="messageImage" Height="359" Width="177"></Image>
                </Border>
                <Button Name="ChangeImagebtn" Background="white" Content="Change Image" Grid.Row="2" Margin="21,2,0,-2" Click="ChangeImagebtn_Click"></Button>
            </Grid>
        </DockPanel>

    </DockPanel>

when i run the program the save button is getting to be selected for some reason and i dont want it to be.
thanks in advance for your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2024-10-15 07:59:33

我认为第一个按钮是被选中的按钮 - 但我很可能是错的。

您可以通过设置 IsDefault 属性设置为 true。

如果要将焦点设置到文本框,则可以

FocusManager.FocusedElement="{Binding ElementName=myTextBox}"

Window 定义中使用:。

MSDN 页面

I think that the first button is the one that gets selected - but I could well be wrong on that.

You can specify which button you want to be the default by setting the IsDefault property of another button to true.

If you want to set the focus to a text box then you can use:

FocusManager.FocusedElement="{Binding ElementName=myTextBox}"

in the Window definition.

MSDN page

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文