Textboxes shouldn't be this hard to access. I want to get a few pertinent info pieces from my user for a process and am trying to access some textboxes that I have created on either a pane or a window. Am not able to find a simple way to get the text out of the textbox.
Solved! Go to Solution.
I figured out a way that works for me. In the Dockpane.xaml, add an x:Name= property to the TextBox like this:
<TextBox x:Name="txtWatPolyElev" HorizontalAlignment="Left" Height="23"................
Then in the Dockpane.xaml.cs in the Button_Click method, access the text using the name like this:
string strElev = txtWatPolyElev.Text;
Simple and it works for me.
Hi Sam,
I believe you can add the dock pane at the moment.
You will notice there are two files added into your project *.xaml and *viewmodel.cs
Double click and open the xaml file, you shall replace grid tag with below.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" LastChildFill="true" KeyboardNavigation.TabNavigation="Local" Height="30">
<TextBlock Grid.Column="1" Text="{Binding Heading}" Style="{DynamicResource Esri_TextBlockDockPaneHeader}">
<TextBlock.ToolTip>
<WrapPanel Orientation="Vertical" MaxWidth="300">
<TextBlock Text="{Binding Heading}" TextWrapping="Wrap"/>
</WrapPanel>
</TextBlock.ToolTip>
</TextBlock>
</DockPanel>
<StackPanel Grid.Row="1" Margin="5">
<TextBlock HorizontalAlignment="Left" Text="Your text" VerticalAlignment="Center"/>
<TextBox Name="txtDebugMessage" MinWidth="250" Text="{Binding Path=DebugMessage}" ></TextBox>
</StackPanel>
<StackPanel Grid.Row="2">
<Button Name="btnDisplayMessage" Command="{Binding Path=CmdDisplayMessage}" HorizontalAlignment="Left" Width="auto" >Display Message</Button>
</StackPanel>
</Grid>
In your *viewmodel.cs, append the below code.
private string _debugMessage;
public string DebugMessage
{
get
{
return _debugMessage;
}
set
{
if (this._debugMessage != value)
{
this._debugMessage = value;
this.NotifyPropertyChanged();
}
}
}
private ICommand _cmdDisplayMessage;
public ICommand CmdDisplayMessage
{
get
{
return _cmdDisplayMessage ?? (_cmdDisplayMessage = new RelayCommand(() =>
{
//Should not use QueueTask with OpenItemDialog
MessageBox.Show($"{DebugMessage}");
}));
}
}
I figured out a way that works for me. In the Dockpane.xaml, add an x:Name= property to the TextBox like this:
<TextBox x:Name="txtWatPolyElev" HorizontalAlignment="Left" Height="23"................
Then in the Dockpane.xaml.cs in the Button_Click method, access the text using the name like this:
string strElev = txtWatPolyElev.Text;
Simple and it works for me.