![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | WPF UI not Refreshing Environment: Visual Studio 2005 with WPF Ext (C#) Windows XP I created a usercontrol that binds to a global object, but when the value of the global object change the fields on the UI is not refreshing. Can someone please let me know what the problem is? Below is an example solution using System; using System.Collections.Generic; using System.Text; namespace WindowsApplication3 { public partial class App : System.Windows.Application { [STAThreadAttribute()] public static void Main() { WindowsApplication3.App app = new WindowsApplication3.App(); Customer cc = new Customer(); cc.FirstName = "John"; cc.LastName = "Doe"; GlobalObj.Instance.CurrentCustomer = cc; app.Run(new Window1()); } } } <Window x:Class="WindowsApplication3.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WindowsApplication3" Height="300" Width="300" Quote: > <StackPanel> <Frame Name="MainPageFrame" Grid.Row="1" Source="Page1.xaml" NavigationUIVisibility="Hidden"/> <Button Name="btChangeCustomer" Margin="0,0,6,0" Click="OnClickChangeCustomer">Change Customer</Button> </StackPanel> </Grid> </Window> using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace WindowsApplication3 { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : System.Windows.Window { public Window1() { InitializeComponent(); } void OnClickChangeCustomer(object sender, RoutedEventArgs e) { Customer cc1 = new Customer(); cc1.FirstName = "Jane"; cc1.LastName = "Smith"; GlobalObj.Instance.CurrentCustomer = cc1; } } } <Page x:Class="WindowsApplication3.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:UI="clr-namespace:WindowsApplication3" Title="Page1" Quote: > <UI:UserControl1 /> </Grid> </Page> <UserControl x:Class="WindowsApplication3.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Quote: > <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="6"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="6"/> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Label Grid.Row="0" Grid.Column="0">FirstName</Label> <TextBox x:Name="CFirstName" Grid.Row="0" Grid.Column="2" Width="150" Text="{Binding FirstName,Mode=OneWay}" /> <Label Grid.Row="2" Grid.Column="0">LastName</Label> <TextBox Grid.Row="2" Grid.Column="2" x:Name="CLastName" Width="150" Text="{Binding LastName,Mode=OneWay}" /> </Grid> </UserControl> using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WindowsApplication3 { /// <summary> /// Interaction logic for UserControl1.xaml /// </summary> public partial class UserControl1 : System.Windows.Controls.UserControl { private delegate void MyDelegate(); public UserControl1() { InitializeComponent(); GridContainer.DataContext = GlobalObj.Instance.CurrentCustomer; } } } using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; namespace WindowsApplication3 { public class GlobalObj : INotifyPropertyChanged { static GlobalObj instance = new GlobalObj(); static GlobalObj() { } GlobalObj() { } public static GlobalObj Instance { get { return instance; } } private Customer _CurrentCustomer; public Customer CurrentCustomer { get { return _CurrentCustomer; } set { _CurrentCustomer = value; OnPropertyChanged("CurrentCustomer"); } } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { if (this.PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } using System; using System.Collections.Generic; using System.Text; namespace WindowsApplication3 { public class Customer { private string _FirstName; public string FirstName { get { return _FirstName; } set { _FirstName = value; } } private string _LastName; public string LastName { get { return _LastName; } set { _LastName = value; } } } } |
My System Specs![]() |
| | #2 (permalink) |
| | RE: WPF UI not Refreshing Hi Simon I take a swift view into your code. Looks like you have to implement the INotifyPropertyChanged Interface in to your Customers class. Best regards Horst |
My System Specs![]() |
| | #3 (permalink) |
| | RE: WPF UI not Refreshing The INotifyPropertyChanged was implemented but the problem was with the TextBox control so I ending up using the ListBox control instead and it work fined "Horst Klein" wrote: Quote: > Hi Simon > > I take a swift view into your code. > Looks like you have to implement the INotifyPropertyChanged Interface in to > your Customers class. > > Best regards > Horst |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| SCVMM refreshing | Virtual Server | |||
| Explorer Keeps Refreshing | Vista performance & maintenance | |||
| Folders Not Refreshing | Vista General | |||
| Re: Refreshing Web Pages in IE7 | Vista security | |||
| Desktop Not Refreshing | General Discussion | |||