1
WPF的新手。我试图在更新依赖项属性值'HasProblem'设置为true时使AvalonDock DocumentHeader的选项卡闪烁。下面是一个代码示例,我明白我需要创建一个DocumentHeaderTemplate并使用DataTemplate.Triggers,或许是绑定到HasProblem的DataTrigger,但我实际上对实现步骤不确定。此外,如果任何人都可以推荐一个关于WPF的综合视频教程,也许涵盖了一些用来实现闪动标签的技术,我将非常感激。WPF AvalonDock使DocumentHeader选项卡闪烁绑定到依赖项属性
<Window x:Class="AirportTab.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:AirportTab"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
d:DataContext="{d:DesignInstance Type=local:AirportCodeDataSource, IsDesignTimeCreatable=True}"
Title="MainWindow" Height="300" Width="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Click="OnToggleErrorClick">
<StackPanel Orientation="Horizontal">
<Label Content="{Binding HasProblem}" ContentStringFormat="HasProblem={0}. Click to change" />
</StackPanel>
</Button>
<ad:DockingManager Grid.Row="1">
<ad:LayoutRoot>
<ad:LayoutPanel Orientation="Horizontal">
<ad:LayoutDocumentPaneGroup>
<ad:LayoutDocumentPane>
<ad:LayoutDocument Title="Airport Code">
<StackPanel>
<DataGrid ItemsSource="{Binding View}" />
</StackPanel>
</ad:LayoutDocument>
</ad:LayoutDocumentPane>
</ad:LayoutDocumentPaneGroup>
</ad:LayoutPanel>
</ad:LayoutRoot>
</ad:DockingManager>
</Grid>
</Window>
public class AirportCode
{
public string Name { get; set; }
public bool Operational { get; set; }
}
public class AirportCodeDataSource : DependencyObject
{
public AirportCodeDataSource()
{
this.View = new ObservableCollection<AirportCode>
{
new AirportCode {Name = "JFK", Operational = true},
new AirportCode {Name = "LHR", Operational = true},
new AirportCode {Name = "LGW", Operational = true}
};
}
public static readonly DependencyProperty HasProblemProperty =
DependencyProperty.Register(
"HasProblem",
typeof(bool),
typeof(AirportCodeDataSource));
public bool HasProblem
{
get { return (bool)GetValue(HasProblemProperty); }
set { SetValue(HasProblemProperty, value); }
}
public ObservableCollection<AirportCode> View { get; set; }
}
public partial class MainWindow : Window
{
public MainWindow()
{
this.DataContext = new AirportCodeDataSource();
InitializeComponent();
}
private void OnToggleErrorClick(object sender, RoutedEventArgs e)
{
this.AirportCodeDataSource.HasProblem = !this.AirportCodeDataSource.HasProblem;
}
public AirportCodeDataSource AirportCodeDataSource { get { return this.DataContext as AirportCodeDataSource; }}
}
非常感谢您的回复。但是,如果我卸下窗户,那么效果很好,但不再有效。这是否是由于在绑定声明中使用RelativeSource?当窗户脱开时,怎么能达到同样的效果?再次感谢你。 – jacko 2015-01-12 16:32:32