I currently have two windows, my main application window and then I have a “Editor” window which is used to change certain things within a TreeView (these are departments) I have recently implemented the ability to hide all sub departments/show, however I have an issue where if I hide/show all of these only the original selection will be hidden/showing until I use my Refresh Function… So my question is.. Is there anyway I can set my accept button on my editor to cause a Refresh of my page as since these are both two seperate files I seem to be unable to access the TreeView named “explorer”
How my current refresh is done:
public void RefreshData()
{
explorer.Items.Clear();
using (new SessionConnecter(session))
{
var topLevelDepartments = session.CreateCriteria(typeof(Department))
.Add(NHibernate.Expression.Expression.Eq(Department.IS_TOP_LEVEL, true))
.List<Department>();
foreach (Department d in topLevelDepartments)
{
explorer.Items.Add(Fabric.ObjectProvider.Get<INodeWrapperFactory>().Create(d));
}
}
}
Current code of saving:
void Save(object sender, ExecutedRoutedEventArgs e)
{
FocusManager.SetFocusedElement(GetWindow(savebutton), savebutton);
if (!session.IsConnected)
session.Reconnect();
try
{
if (ValidateModel())
{
session.Save(model);
if (pendingParent != null)
{
model.Parent = pendingParent;
// session.Save(pendingParent); - should cascade
}
session.Flush();
Close();
}
}
catch (NHibernate.Classic.ValidationFailure ex)
{
if (pendingParent != null)
session.Refresh(pendingParent);
if (session.IsConnected)
session.Disconnect();
MessageBox.Show(this, ex.Message, this.Title, MessageBoxButton.OK, MessageBoxImage.Warning);
}
}
In this case, a solution could be using Messages. Do you have seen the Mvvm Light Toolkit’s messages? This is a good way of communicate distances objects, other windows, etcs. You may to implement you self message mechanism, by making an static class (the same for all the application) then implement your own subscription/calling mechanism… Hope be helpful to you.