On refresh button, I call _eventAggregator.GetEvent<RefreshEvent>().Publish();
And code in all regions in tabs had subscribed to this event.
Problem: The problem is that I want to update only currently active tab. But in my case all tabs are updating. Is there a good practices to solve this?
Edit 1
I implement IActiveAware
in my view:
public partial class ShipsControlView : UserControl, IActiveAware
{
public ShipsControlView()
{
InitializeComponent();
}
private bool isActive;
public bool IsActive
{
get
{
return this.isActive;
}
set
{
if (this.isActive == value)
return;
this.isActive = value;
var viewModelActiveAware = this.DataContext as IActiveAware;
if (viewModelActiveAware != null)
viewModelActiveAware.IsActive = value;
this.OnIsActiveChanged();
}
}
public event EventHandler IsActiveChanged;
protected virtual void OnIsActiveChanged()
{
var handler = this.IsActiveChanged;
if (handler != null)
handler(this, EventArgs.Empty);
}
}
Added this view to tabControl:
<TabControl
prism:RegionManager.RegionName="TabRegion2"
ItemContainerStyle="{StaticResource HeaderStyle}"
></TabControl>
.
regionManager.RegisterViewWithRegion("TabRegion2", typeof(ShipsControlView));
I check the status of IsActive
, it is always changed if I click tabs (works right).
Problem: If tab is not active, the commands in that tab triggering on my global composite button, but it must not.
You shouldn't be using the event aggregator for this. You should be using CompositeCommands. They even monitor active tabs/VMs when they implement IActiveAware automatically.
Here is the docs: http://prismlibrary.readthedocs.io/en/latest/WPF/09-Communication/#solution-commanding