Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - WPF UI not Refreshing

 
 
Old 11-12-2007   #1 (permalink)
Simon


 
 

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:

>
<Grid>
<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:

>
<Grid>
<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 x:Name="GridContainer" Margin="10" >
<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 SpecsSystem Spec
Old 12-07-2007   #2 (permalink)
Horst Klein


 
 

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 SpecsSystem Spec
Old 12-07-2007   #3 (permalink)
Simon


 
 

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 SpecsSystem Spec
 

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46