473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

wpf TwoWay bindin issue

Hi there guys

I have a problem with TwoWay binding porcess.
On the code I have a TextBox, Button and 3 checkBox
I want to update the TextBox when i press the button.
When i use the checkbox i define TwoWay binding for each checkbox and I also define the Click event (for the main checkbox - ValidatAll). In that way a click on a checkbox effect the other checkboxes (for example if all values are false, a click of Validate all will turn all of them to true and the checkboxes will show as checked)
The problem is when i try to do the same trick on the TextBox using the button as triger.
The button open a file browser that return a string. i take this string and issue it to the TextBox.Text field. this Field is define as TwoWay Binding...
The problem is that this code update just the Gui, but it doesn't update the logic (it seems like i am missing an event here).

For example lets say i want to issue c:\temp into the TextBox.
If i will write "c:\temp", the "WindowsRootProperty" will get the string value.
When i use the browsing button, the TextBox.Text is updated but the "WindowsRootProperty" never called...

can anyone help?
see attached code

i am using WPF - .NET3.5
here is my code sample (I reduce the code by removing the non-relevant design code):

Window1.xaml:
Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="scomp.Window1"
  2.                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.                     xmlns:src="clr-namespace:scomp"
  5.                     <Window.Resources>
  6.                         <src:UserData x:Key="myUserData"/>
  7.                     </Window.Resources>
  8.                     <Window.DataContext>
  9.                         <Binding Source="myUserData"/>
  10.                     </Window.DataContext>
  11.  
  12.                     <Grid Name="scomp">
  13.                         <TextBox Name="winRootData" 
  14.                                  Text="{Binding Path=WindowsRootProperty, Source={StaticResource myUserData}, Mode=TwoWay}">
  15.                         </TextBox>
  16.                         <Button Name="winRootButton"  
  17.                                 Height="30" 
  18.                                 Width="90" 
  19.                                 Click="winRootButton_Click">Browse...
  20.                         </Button>        
  21.                         <CheckBox x:Name="VlaidateAll" 
  22.                                   Content="Validation" 
  23.                                   Margin="30,0,0,0" 
  24.                                   IsChecked="{Binding Path=AllValidateProperty, Source={StaticResource myUserData}, Mode=TwoWay}" 
  25.                                   Click="VlaidateAll_Click">
  26.                         </CheckBox>
  27.                         <CheckBox x:Name="InputValidation" 
  28.                                   Content="Input Validation"  
  29.                                   IsChecked="{Binding Path=InputValidateProperty, Source={StaticResource myUserData}, Mode=TwoWay}">
  30.                         </CheckBox>
  31.                         <CheckBox x:Name="TriggerValidation" 
  32.                                   Content="Trigger Validation" 
  33.                                   IsChecked="{Binding Path=TriggerValidateProperty, Source={StaticResource myUserData}, Mode=TwoWay}" >
  34.                         </CheckBox>
  35.                     </Grid>
  36.                 </Window>
  37.  
  38.  
  39. Window1.xaml.cs:
  40.  
  41.                 public partial class Window1 : Window
  42.                 {
  43.                     FolderBrowserDialog fbd = new FolderBrowserDialog();
  44.  
  45.                     public Window1()
  46.                     {
  47.                         InitializeComponent();
  48.                     }
  49.  
  50.                     private void VlaidateAll_Click(object sender, RoutedEventArgs e)
  51.                     {
  52.                         if ((sender as System.Windows.Controls.CheckBox).IsChecked == true)
  53.                         {
  54.                             this.InputValidation.IsChecked = true;
  55.                             this.TriggerValidation.IsChecked = true;                
  56.                         }
  57.                         else
  58.                         {
  59.                             this.InputValidation.IsChecked = false;
  60.                             this.TriggerValidation.IsChecked = false;
  61.                         }
  62.                     }
  63.  
  64.                     private void winRootButton_Click(object sender, RoutedEventArgs e)
  65.                     {
  66.                         fbd.SelectedPath = this.winRootData.Text;            
  67.                         fbd.ShowNewFolderButton = false;
  68.                         fbd.ShowDialog();
  69.                         this.winRootData.Text = fbd.SelectedPath;   
  70.                         fbd.SelectedPath = null;
  71.                     }
  72.                 }
  73.  
  74. UserData.cs:
  75.  
  76.                 public class UserData : INotifyPropertyChanged
  77.                 {
  78.                     private bool? vAllValidate;
  79.                     private bool? vInputValidate;
  80.                     private bool? vTriggerValidate;
  81.                     private string mWinRoot;
  82.  
  83.                    public event PropertyChangedEventHandler PropertyChanged;
  84.  
  85.                     public UserData()
  86.                     {
  87.                         vAllValidate = false;
  88.                         vInputValidate = false;
  89.                         vTriggerValidate = false;
  90.  
  91.                         mWinRoot = null;
  92.                     }
  93.  
  94.                     public string WindowsRootProperty
  95.                     {
  96.                         set
  97.                         {
  98.                             mWinRoot = value;
  99.                             OnPropertyChanged("WindowsRootProperty");
  100.                         }
  101.                         get
  102.                         {
  103.                             return mWinRoot;
  104.                         }
  105.                     }
  106.                     public bool? AllValidateProperty
  107.                     {
  108.                         set 
  109.                         {
  110.                             vAllValidate = value;
  111.                             OnPropertyChanged("AllValidateProperty");
  112.                         }
  113.                         get 
  114.                         {
  115.                             return vAllValidate;
  116.                         }
  117.                     }
  118.                     public bool? InputValidateProperty
  119.                     {
  120.                         set
  121.                         {
  122.                             vInputValidate = value;
  123.                             OnPropertyChanged("InputValidateProperty");
  124.                             if (value == true)
  125.                             {
  126.                                 if (vAllValidate == false)
  127.                                 {
  128.                                     AllValidateProperty = true;
  129.                                 }
  130.                             }
  131.                             else
  132.                             {
  133.                                 if (vAllValidate == true && vTriggerValidate == false)
  134.                                 {
  135.                                     AllValidateProperty = false;
  136.                                 }
  137.                             }                
  138.                         }
  139.                         get
  140.                         {
  141.                             return vInputValidate;
  142.                         }
  143.                     }
  144.                     public bool? TriggerValidateProperty
  145.                     {
  146.                         set
  147.                         {
  148.                             vTriggerValidate = value;
  149.                             OnPropertyChanged("TriggerValidateProperty");
  150.                             if (value == true)
  151.                             {                    
  152.                                 if (vAllValidate == false)
  153.                                 {
  154.                                     AllValidateProperty = true;
  155.                                 }
  156.                             }
  157.                             else
  158.                             {
  159.                                 if (vAllValidate == true && vInputValidate == false)
  160.                                 {
  161.                                     AllValidateProperty = false;
  162.                                 }
  163.                             }
  164.                         }
  165.                         get
  166.                         {
  167.                             return vTriggerValidate;
  168.                         }
  169.                     }
  170.                     protected void OnPropertyChanged(string str)
  171.                     {
  172.                         if (PropertyChanged != null)
  173.                         {
  174.                             PropertyChanged(this, new PropertyChangedEventArgs(str));
  175.                         }
  176.  
  177.                     }
  178.                 }
Jul 17 '11 #1
0 1344

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
7
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with...
2
by: Anthony Cuttitta Jr. | last post by:
We have an application that outputs several different graphs from data downloaded from our AS400. The application has worked without (this) issue for several months now, but just recently, the...
0
by: Kevin Spencer | last post by:
Hi all, I am working on a service that uploads METAR weather information to the National Weather Service FTP site. The service I'm authoring is hosted on a Windows 200 server, and the NWS FTP...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
0
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". ...
4
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
0
by: nelsonbrodyk | last post by:
Hey All, I have been able to set up a databinding to a property with the following code: <TextBox x:Name="txtTextBox" Text="{Binding Path=NameFirst, Mode=TwoWay,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.