我有一個tabcontrol的數據模式,我綁定到一個視圖列表。 我希望用BusyIndicator包裝每個視圖,並將BusyIndicator的IsBusy屬性綁定到視圖IsBusy屬性。 這是模板:綁定到子視圖中的datacontext
<TabControl ItemsSource="{Binding ViewModels}" x:Name="TabControlViews">
<TabControl.ItemTemplate>
<!-- this is the header template-->
<DataTemplate>
<TextBlock
Text="{Binding Title}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<!-- this is the body of the TabItem template-->
<DataTemplate>
<xctk:BusyIndicator IsBusy="{Binding DataContext.IsBusy, RelativeSource={RelativeSource FindAncestor,AncestorType=ContentControl}}">
<xctk:BusyIndicator.BusyContent>
<TextBlock Text="Vent venligst ..." VerticalAlignment="Center" />
</xctk:BusyIndicator.BusyContent>
<ContentControl Content="{Binding View}"/>
</xctk:BusyIndicator>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
這是爲每個標籤
public class TabViewModel : INotifyPropertyChanged
{
private ContentControl _view;
public string Title { get; set; }
public ContentControl View
{
get { return _view; }
set { _view = value; OnPropertyChanged();}
}
public ViewType ViewTypeToLoadType { get; set; }
public bool IsLoaded { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
視圖模型於是路徑我要綁定的屬性是正確的: ContentControl.DataContext.View.DataContext .sbusy
可能嗎?
這是在視圖模型,但具有IsBusy屬性視圖模型是生活在裝上TabViewModel.View的看法。 –
我編碼的是我自己的替代棱鏡區域以加載視圖時有更多的控制權。 –