将文本从一个文本框复制到另一个基于WPF的复选框控件 [英] Copy Text from one textbox to another based checkbox control in WPF

查看:170
本文介绍了将文本从一个文本框复制到另一个基于WPF的复选框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我有两个文本框和一个窗口中的复选框,我有以下场景要见

1。检查CheckBox时应启用Textbox2

2.如果未选中CheckBox,则在文本框1中按键时将文本从Textbox1复制到Textbox2(即同时动态)



我可以通过将IsEnabled属性绑定到Checkbox的IsChecked属性来完成第一部分,并且它工作正常



我被困在第二部分部分因为有一个事件触发器(在Textbox1上),它应该根据另一个控件(Checkbox)的某个属性值触发并更新第三个控件的Text属性(Textbox2)。怎么做到这一点?任何帮助请



我不想为此使用任何代码,虽然我甚至不想使用任何ViewModel属性或ICommand属性来处理这个要么除非另有说明!想知道是否有一个简单的XAML方式这样做。



以下是当前XAML的样子



Hello,

I am having 2 textboxes and a checkbox in a window, I am having following scenarios to meet
1. Textbox2 should be enabled when CheckBox is checked
2. If CheckBox is not checked then copy text from Textbox1 to Textbox2 on key press in Textbox1 (i.e. simultaneously on the fly)

I am able to complete the first part by binding IsEnabled property to Checkbox's IsChecked property and it works fine

I am stuck with the second part as there an event trigger (on Textbox1) which should fire based on certain property value of another control (Checkbox) and update Text property of 3rd control (Textbox2). How to achieve this? Any help please

I don't want to use any code behind for this, although I don't even want to use any ViewModel property or ICommand property to handle this either unless otherwise not possible!! Was wondering if there's a simple "XAML way" of doing this.

Below is what the current XAML looks like

<TextBox Name="txt1" HorizontalAlignment="Left" Height="23" Margin="68,73,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <TextBox IsEnabled="{Binding ElementName=chkbx, Path=IsChecked}" Name="txt2" Text="{Binding ElementName=txt1, Path=Text}" HorizontalAlignment="Left" Height="23" Margin="68,155,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120">
            <!--
            If checkbox is not checked don't copy text from txt1
            -->
        </TextBox>
        <CheckBox Content="CheckBox" Name="chkbx" HorizontalAlignment="Left" Margin="68,116,0,0" VerticalAlignment="Top"/>







此致,

Sujay C.




Regards,
Sujay C.

推荐答案

发布一些代码,我们将非常乐意为您提供帮助。
Post some code, then we will be more than happy to help you.


这篇关于将文本从一个文本框复制到另一个基于WPF的复选框控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆