在刷新按钮上,我打电话_eventAggregator.GetEvent<RefreshEvent>().Publish();
并且标签中所有区域的代码都订阅了这个事件。
问题: 问题是我只想更新当前活动的选项卡。但就我而言,所有选项卡都在更新。有没有解决这个问题的好习惯?
编辑 1
我IActiveAware
在我看来实现:
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);
}
}
将此视图添加到 tabControl:
<TabControl
prism:RegionManager.RegionName="TabRegion2"
ItemContainerStyle="{StaticResource HeaderStyle}"
></TabControl>
.
regionManager.RegisterViewWithRegion("TabRegion2", typeof(ShipsControlView));
我检查 的状态IsActive
,如果我单击选项卡,它总是会改变(正常工作)。
问题: 如果选项卡未处于活动状态,则该选项卡中的命令会在我的全局复合按钮上触发,但不能。