XAML DataTrigger problem

J

J.F. Ronner

Hello,

I am making a mess of a project in which I use XAML DataTriggers..

My purpose is to display a boolean on a form (Window) which works
fine, but when the boolean value changes, the DataTrigger does not
update the value.

I don't know how to fix this. How can I refresh the DataTrigger?

I pasted the source files here:

Window1.xaml.cs
http://pastebin.com/m5980eb14

Window1.xaml
http://pastebin.com/d33b76e97

You can compile the project if you like.

What am I doing wrong?


Thanks in advance..


Regards,

J.F. Ronner
 
G

Geoffrey Summerhayes

Hello,

I am making a mess of a project in which I use XAML DataTriggers..

My purpose is to display a boolean on a form (Window) which works
fine, but when the boolean value changes, the DataTrigger does not
update the value.

I don't know how to fix this. How can I refresh the DataTrigger?

I pasted the source files here:

Window1.xaml.cshttp://pastebin.com/m5980eb14

Window1.xamlhttp://pastebin.com/d33b76e97

You can compile the project if you like.

What am I doing wrong?

Thanks in advance..

Regards,

J.F. Ronner

I'm waiting for 'IsModified' to change.
Oooooh, 'someFlag' changed.
Why should I care if 'someFlag' changes?
Nothing to do with me, I'm waiting for 'IsModified' to change.
 
J

J.F. Ronner

I'm waiting for 'IsModified' to change.
Oooooh, 'someFlag' changed.
Why should I care if 'someFlag' changes?
Nothing to do with me, I'm waiting for 'IsModified' to change.

Don't make me look like a fool.

I tried that, you know.

It is the IDEA that just does not work..
 
G

Geoffrey Summerhayes

Don't make me look like a fool.

WTF?

Taking posts too seriously and interpreting things as
personal insults is your problem, not mine.
I tried that, you know.

I know now.
It is the IDEA that just does not work

Well, the XAML appears to have evaporated all I have is the
C#.

Numerous points:

- Get rid of the destructor move that code to the Closed event.
That destructor is unlikely to ever be called while the thread is
running and the thread will keep running until the destructor is
called.
- What is TestClass supposed to be? It looks partially like a
Singleton pattern but has a public constructor that never gets
called.
- There's nothing in the C# that actually connects an instance
of the class to the XAML.
 
G

Geoffrey Summerhayes

Try this:

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Closed="Window_Closed">
</Grid>
</Window>

public partial class Window1 : Window
{
private bool blink = true;
private Thread aThread = null;
private bool runThread = true;

public Window1()
{
InitializeComponent();

aThread = new Thread(testThread);
aThread.Start();

Check.DataContext = TestClass.Instance;
}

private void testThread()
{
while (runThread)
{
blink = !blink;
Debug.WriteLine(string.Format("Setting blink to {0}",
blink.ToString()));
TestClass.Instance.IsModified = blink;
Thread.Sleep(1000);
}
}

private void Window_Closed(object sender, EventArgs e)
{
runThread = false;
}
}

/// <summary>
/// Represents an entity loaded from the database.
/// </summary>
public class TestClass : INotifyPropertyChanged
{
private bool someFlag = false;
private static TestClass theInstance = new TestClass();

private TestClass()
{
}

public static TestClass Instance { get { return
theInstance; } }

/// <summary>
/// Gets a value that indicates if the entity has been
modified
/// since it was loaded.
/// </summary>
public Boolean IsModified
{
get
{
return someFlag;
}
set
{
if (someFlag != value)
{
someFlag = value;
NotifyPropertyChanged("IsModified");
}
}
}

#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;

private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
Debug.WriteLine("NotifyPropertyChanged()");
PropertyChanged(this, new PropertyChangedEventArgs
(info));
}
}
#endregion
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top