简体   繁体   English

从一个文本框到另一个XAML获取价值

[英]Get value from one textbox to another XAML

I have created a text box which when focused brings up a popup box with other text box's as options.. and when pressed closes the popup box.. but I'd like that to then take the value from whichever text box I have selected and add into the original text box. 我创建了一个文本框,当集中显示时会弹出一个带有其他文本框作为选项的弹出框..当按下时会关闭该弹出框..但是我希望从任何一个我选择的文本框中取值,然后添加到原始文本框中。 Is this possible? 这可能吗? I'm new to wpf so forgive me! 我是wpf的新手,请原谅我!

Here is my code so far. 到目前为止,这是我的代码。

 <Grid>

    <StackPanel Margin="0,51,0,-51">
        <TextBox  x:Name="text" GotKeyboardFocus="text_GotKeyboardFocus" Margin="158,0,169,0" Height="24" Text="Select Your Time..." />

        <Popup x:Name="popup" Width="282" Height="300" PlacementTarget="{Binding ElementName=text}">
            <Grid>
                <StackPanel>
                    <TextBox  x:Name="text2" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="1 second" />
                    <TextBox  x:Name="text3" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="2 second" />
                    <TextBox  x:Name="text4" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="3 second" />
                    <TextBox  x:Name="text5" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="4 second" />
                    <TextBox  x:Name="text6" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="5 second" />
                </StackPanel>
            </Grid>
        </Popup>

    </StackPanel>




</Grid>




 private void text_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
    {
        popup.IsOpen = true;
    }

    private void text_GotKeyboardFocus2(object sender, RoutedEventArgs e)
    {
        popup.IsOpen = false;
    }

Get value from one textbox to another in xaml: 在xaml中从一个文本框获取价值到另一个文本框:

<TextBox Name="txtBox1"/>

<TextBox Name="txtBox2" Text="{Binding ElementName=txtBox1, Path=Text,UpdateSourceTrigger=PropertyChanged}" />

I hope I got your point. 希望我明白你的意思。
Just add text.Text = (sender as TextBox).Text; 只需添加text.Text = (sender as TextBox).Text; to your second event handler as follows : 到您的第二个事件处理程序,如下所示:

private void text_GotKeyboardFocus2(object sender, RoutedEventArgs e)
{
     popup.IsOpen = false;
     text.Text = (sender as TextBox).Text;
}

Good luck. 祝好运。

Get value from one textbox to another XAML 从一个文本框到另一个XAML获取价值

<TextBox Name="txtBox1"/>

<TextBox Name="txtBox2" Text="{Binding ElementName=txtBox1, Path=Text,UpdateSourceTrigger=PropertyChanged}" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM