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