Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

XML
<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"/>



Regards,
Sujay C.
Posted
Updated 10-Sep-15 19:26pm
v2
Comments
Sergey Alexandrovich Kryukov 8-Sep-15 0:55am    
Your "I don't want..." should be properly motivated, otherwise who would like to waste time on some freaking "requirements"?
—SA
SujayC 8-Sep-15 1:33am    
Sorry, I didn't understood what your meant by that.... nevertheless, this was something I came up while learning WPF so not a "requirement" to be precise...
Sergey Alexandrovich Kryukov 8-Sep-15 1:48am    
Which part of my statement you don't understand? Call it "not requirement", but you put constraint on possible solutions, say, do it, but not this way and not that way. If you want someone spend time on this, you have to explain, why not.
—SA
SujayC 8-Sep-15 1:50am    
Okay.... as I said, I am learning WPF so was wondering if there's a way using xaml only to achieve this behavior?
Sergey Alexandrovich Kryukov 8-Sep-15 1:56am    
Yes, I understood it in first place. I just don't think this intellectual exercise worth any effort; it does not present any theoretical or practical interest. If you think that XAML purism makes any sense, I'm not going to agree.
—SA

1 solution

Post some code, then we will be more than happy to help you.
 
Share this answer
 
Comments
SujayC 11-Sep-15 1:27am    
sample code is added.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900