How to refresh a Binding from another thread ?

Using Microsoft Windows Presentation Foundation and Syncfusion WPF Libraries

How to refresh a Binding from another thread ?

Postby PGilbert on Thu Aug 03, 2017 11:50 pm

If you fix the following two functions in a )CLEAR WS:

      test;binding;str;types;xaml;xml;⎕USING

⎕USING←'System.IO'
⎕USING,←⊂'System'
⎕USING,←⊂'System.Windows.Markup'
⎕USING,←⊂'System.Xml,system.xml.dll'
⎕USING,←⊂'System.Windows.Controls,WPF/PresentationFramework.dll'

xaml←'<Window '
xaml,←' xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"'
xaml,←' xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" '
xaml,←' xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"'
xaml,←' xmlns:local="clr-namespace:testlibrary" '
xaml,←' Title="Window" Height="300" Width="300"> '
xaml,←' <Grid > '
xaml,←' <StackPanel DataContext="{Binding MyValues}"> '
xaml,←' <TextBox Text="{Binding TextValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"></TextBox> '
xaml,←' </StackPanel> '
xaml,←' </Grid> '
xaml,←'</Window>'

str←⎕NEW StringReader(⊂xaml)
xml←⎕NEW XmlTextReader str
win←XamlReader.Load xml

props←⎕NS''
props.MyValues←⎕NS''
props.MyValues.TextValue←'this is working'

binding←(2015⌶)'props'

win.DataContext←binding
win.Show


      refreshBind ra
props.MyValues.TextValue←ra


Then if you execute the function 'test' you get a WPF window as expected with the TextBox text as: 'this is working'. After that if you execute the function 'refreshBind' you can change the value of the TextBox as expected. But if you try to refresh the namespace with 'refreshBind&' from another thread it is not working. Is there a way to make this work ?

      test
refreshBind 'this is working'
refreshBind& 'this is NOT working'


Thanks in advance,

Pierre Gilbert
User avatar
PGilbert
 
Posts: 356
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Return to WPF & Syncfusion

Who is online

Users browsing this forum: No registered users and 1 guest