Hello,
I have an Avalondock that incorporates both a LayoutDocumentPane and an LayoutAnchorablePane the DocumentsSource and AnchorablesSource both binding to the same datasource which in this case returns a collection of airport codes and airline codes.
![Image]()
What I have currently is when I check an airline code both the tab in the Document pane and also the tab in the Anchorable pane have style applied to change the background color of the tab.
What I have at the moment when checking the check box![Image]()
What I want is in addition to the background color of the tab being updated when I check a check box I want the appropriate document in the Anchorable pane to be the active content. In the example below the effect I need when checking the check box would be the same as clicking on the tab for LGW from the Anchorable pane, the data for LGW would show. Any pointers on how this could be achieved? Thank you.
What I really want when checking the check box![Image]()
Below is the XAML and code behind that I used
<Window x:Class="AirportTabAlert.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ad="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:local="clr-namespace:AirportTabAlert"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:debug="clr-namespace:System.Diagnostics;assembly=WindowsBase"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Title="MainWindow" Height="350" Width="525">
<Window.DataContext>
<!-- Declaratively create an instance of View Model-->
<local:MainWindowViewModel />
</Window.DataContext>
<Window.Resources>
<Style x:Key="NotifyTab">
<Setter Property="Control.Background" Value="Lime"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding HasProblem}" Value="True">
<Setter Property="Control.Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Control.FontSize" Value="20"></Setter>
<Setter Property="Control.HorizontalAlignment" Value="Center"></Setter>
<Setter Property="Control.Margin" Value="10"></Setter>
<Setter Property="Control.Foreground" Value="Black"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=textBox1, Path=Text.Length}" Value="0">
<Setter Property="IsEnabled" Value="False"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.Resources>
<Style x:Key="ErrorButtonStyle" TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding HasProblem}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel>
<TextBox Height="23" HorizontalAlignment="Left" Name="textBox1" VerticalAlignment="Top" Width="120" />
<ListBox ItemsSource="{Binding DataSources}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding Title}" Command="{Binding UpdateHasProblem}" Margin="5,1,15,1" Name="chkTitle" Click="chkTitle_Click" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
<ad:DockingManager Grid.Row="1" DocumentsSource="{Binding DataSources}" AnchorablesSource="{Binding DataSources}"
ActiveContent="{Binding DocumentManager.ActiveDocument,
Mode=TwoWay}"
>
<ad:DockingManager.DocumentTitleTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis" x:Name="ctrl" Background="Lime" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Content.HasProblem}" Value="True">
<Setter TargetName="ctrl" Property="Background" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ad:DockingManager.DocumentTitleTemplate>
<ad:DockingManager.DocumentHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis" x:Name="ctrl" Background="Lime" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Content.HasProblem}" Value="True">
<Setter TargetName="ctrl" Property="Background" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ad:DockingManager.DocumentHeaderTemplate>
<ad:DockingManager.AnchorableHeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Title}" TextTrimming="CharacterEllipsis" x:Name="ctrl" Background="Lime" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Content.HasProblem}" Value="True">
<Setter TargetName="ctrl" Property="Background" Value="Red"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ad:DockingManager.AnchorableHeaderTemplate>
<ad:DockingManager.LayoutItemTemplate>
<DataTemplate>
<DataGrid ItemsSource="{Binding View}" />
</DataTemplate>
</ad:DockingManager.LayoutItemTemplate>
<ad:DockingManager.LayoutItemContainerStyle>
<Style TargetType="{x:Type ad:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Title}"/>
</Style>
</ad:DockingManager.LayoutItemContainerStyle>
<ad:LayoutRoot x:Name="LayoutRoot" >
<ad:LayoutPanel Orientation="Horizontal">
<ad:LayoutDocumentPane/>
<ad:LayoutAnchorablePane />
</ad:LayoutPanel>
</ad:LayoutRoot>
</ad:DockingManager>
</Grid>
</Window>
namespace AirportTabAlert
{
public class AirportViewModel : ObservableObject
{
private static Random rand = new Random();
public string Title { get; private set; }
public AirportViewModel(string title)
{
string[] airlines = new string[] { "BA", "CX", "AA", "AB", "CCA", "DL" };
this.Title = title;
this.View = new ObservableCollection<Airport>();
for (var i = 0; i < rand.Next(10, 100); i++)
{
this.View.Add(new Airport
{
Name = airlines[rand.Next(0, 5)] + rand.Next(0, 100),
Landed = rand.Next(0, 1) != 0
});
}
}
private bool _HasProblem;
public bool HasProblem
{
get
{
return _HasProblem;
}
set
{
if (_HasProblem != value)
{
_HasProblem = value;
RaisePropertyChanged("HasProblem");
}
}
}
public ObservableCollection<Airport> View { get; set; }
#region Commands
void UpdateHasProblemExecute()
{
HasProblem = !HasProblem;
}
bool CanHasProblemExecute()
{
return true;
}
public ICommand UpdateHasProblem { get { return new RelayCommand(UpdateHasProblemExecute, CanHasProblemExecute); } }
#endregion
}
}
namespace AirportTabAlert
{
public class Airport
{
public string Name { get; set; }
public bool Landed { get; set; }
public bool HasProblem { get; set; }
}
}
namespace AirportTabAlert
{
public class MainWindowViewModel
{
public ObservableCollection<AirportViewModel> DataSources { get; private set; }
public MainWindowViewModel()
{
this.DataSources = new ObservableCollection<AirportViewModel>
{
new AirportViewModel("LHR"),
new AirportViewModel("LGW"),
new AirportViewModel("LCY")
};
}
}
}