how to set a field to be selected by default
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
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
精彩评论