我想在WPF C#中的tabitems的标题中显示一个加载器gif,我的tabitems动态生成,并用特定的图标替换加载器gif(如果可用),因此当我这样做this.tabcontrol.items.refresh我的所有标签会刷新其内容,因此整个屏幕在刷新整个屏幕时都会出现抽搐。
我已经尝试过this.tabcontrol.items.refresh(),但它会刷新所有标签及其内容。
这是样式
<Setter Property="ContentStringFormat" Value="{Binding Path=timergif ,diagnostics:PresentationTraceSources.TraceLevel=High}"></Setter>
<Setter Property="Tag" Value="{Binding Path=LabelText2 ,diagnostics:PresentationTraceSources.TraceLevel=High}"></Setter>
<Setter Property="Header" Value="{Binding Path=LabelText ,diagnostics:PresentationTraceSources.TraceLevel=High}" />
<Style TargetType="{x:Type tab:FabTabItem}">
<Setter Property="ContentStringFormat" Value="{Binding Path=timergif ,diagnostics:PresentationTraceSources.TraceLevel=High}"></Setter>
<Setter Property="Tag" Value="{Binding Path=LabelText2 ,diagnostics:PresentationTraceSources.TraceLevel=High}"></Setter>
<Setter Property="Header" Value="{Binding Path=LabelText ,diagnostics:PresentationTraceSources.TraceLevel=High}" />
<Setter Property="Height" Value="30" />
<Setter Property="Background" Value="{DynamicResource MyFillBrush}" />
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<!--<Image Height="25" Margin="4,0,4,0"
Source="{Binding Tag, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}}}" />-->
<!--<MediaElement Height="25" Width="25" Margin="4,0,4,0" x:Name="myGif" UnloadedBehavior="Manual" Source="Loading_icon.gif" LoadedBehavior="Play" Stretch="None"/>-->
<Image Width="20" gif:ImageBehavior.AnimatedSource="{Binding Tag, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}}}" />
<Label Content="{Binding}"/>
<Image Width="20" gif:ImageBehavior.AnimatedSource="{Binding ContentStringFormat, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}}}" />
<!--<Image Width="20" gif:ImageBehavior.AnimatedSource="{Binding Path=(local:BrowserWindow.LabelText),RelativeSource={RelativeSource TemplatedParent} }" />-->
<!--<StackPanel Orientation="Vertical">
--><!--<Image Height="25" Margin="4,0,4,0"
Source="{Binding Tag, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}}}" />-->
<!--<MediaElement Height="25" Width="25" Margin="4,0,4,0" x:Name="myGif" UnloadedBehavior="Manual" Source="Loading_icon.gif" LoadedBehavior="Play" Stretch="None"/>--><!--
</StackPanel>-->
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<!--<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type tab:FabTabItem}">
<Border Name="Border" BorderThickness="1,1,1,0" BorderBrush="Gainsboro" CornerRadius="4,4,0,0" Margin="2,0">
<ContentPresenter x:Name="ContentSite"
VerticalAlignment="Center"
HorizontalAlignment="Center"
ContentSource="Header"
Margin="10,2"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="LightSkyBlue" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="GhostWhite" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>-->
</Style>
_mainForm.tabControl.Items.Refresh();
我希望仅刷新特定Tabitem标题中的图像。