Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
元素的WPF更改值';伯塞顿的财产_Wpf_Xaml_Styles_Basedon - Fatal编程技术网

元素的WPF更改值';伯塞顿的财产

元素的WPF更改值';伯塞顿的财产,wpf,xaml,styles,basedon,Wpf,Xaml,Styles,Basedon,我有以下风格: <Style TargetType="{x:Type local:MetroTabControl}"> <Style.Triggers> <Trigger Property="SingleRow" Value="True"> <Setter Property="Template"> <Setter.Value>

我有以下风格:

<Style TargetType="{x:Type local:MetroTabControl}">
    <Style.Triggers>
        <Trigger Property="SingleRow" Value="True">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:MetroTabControl}">
                        <Grid>
                            <Grid KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="True">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <Grid>
                                    <ScrollViewer x:Name="ScrollViewer" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Hidden" Style="{DynamicResource TabPanelScrollViewer}">
                                        <TabPanel x:Name="HeaderPanel" IsItemsHost="True" Panel.ZIndex="1" KeyboardNavigation.TabIndex="1"/>
                                    </ScrollViewer>
                                    <Button x:Name="AddTabItem" Content="&#xE109;"  Style="{DynamicResource TabControlButton}" HorizontalAlignment="Right" VerticalAlignment="Top"/>
                                </Grid>
                                <Border Grid.Row="1" x:Name="TabPanelBorder" Background="Transparent">
                                    <Rectangle x:Name="TabPanelBorderRectangle" Fill="{StaticResource TabPanelBorderBrush}" Height="2"/>
                                </Border>
                                <Border Grid.Row="2" Background="{StaticResource TabControlBackground}"/>
                                <ContentPresenter Grid.Row="2" Name="PART_SelectedContentHost" ContentSource="SelectedContent"/>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <!--<Setter Property="Template" Value="{StaticResource MetroTabControlSingleRow}" />-->
        </Trigger>
        <Trigger Property="SingleRow" Value="False">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type local:MetroTabControl}">
                        <Grid KeyboardNavigation.TabNavigation="Local" SnapsToDevicePixels="True">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Border Background="Transparent" BorderThickness="0,0,0,2"  BorderBrush="{StaticResource TabPanelBorderBrush}">
                                <DockPanel LastChildFill="True">
                                    <Button x:Name="AddTabItem" Style="{DynamicResource TabControlButton}" DockPanel.Dock="Right">
                                        <Path Stroke="{Binding Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Button}}}" Data="M0,4 H8 M4,0 V8"  StrokeThickness="2" />
                                    </Button>
                                    <TabPanel x:Name="HeaderPanel" IsItemsHost="True" Panel.ZIndex="1" KeyboardNavigation.TabIndex="1"/>
                                </DockPanel>
                            </Border>
                            <Border Grid.Row="1" Background="{StaticResource TabControlBackground}"/>
                            <ContentPresenter Grid.Row="1" Name="PART_SelectedContentHost" ContentSource="SelectedContent"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <!--<Setter Property="Template" Value="{StaticResource MetroTabControlMultiRows}" />-->
        </Trigger>
    </Style.Triggers>
</Style>
但是我不知道如何从
BasedOn
样式更改选项卡panelborderrectangle
Rectangle
的颜色

我试过类似的东西

<Setter TargetName="TabPanelBorderRectangle" Property="Fill" Value="Red"/>

但它不起作用(不能在样式设置器上设置TargetName属性)


如何执行此操作?

由于错误状态,您不能在样式设置器中使用
TargetName

作为一种解决方法,您可以做的是,使用
DynamicResource
绑定笔刷,而不是使用
StaticResource
,这样我们就可以利用XAML的资源查找行为

<Rectangle x:Name="TabPanelBorderRectangle"
           Fill="{DynamicResource TabPanelBorderBrush}"/>
由于
画笔
是通过
动态资源
绑定的,因此它将从您的样式资源中选择
大多数本地值
,在上述情况下,这些值将为绿色

<Rectangle x:Name="TabPanelBorderRectangle"
           Fill="{DynamicResource TabPanelBorderBrush}"/>
<Style TargetType="{x:Type local:MetroTabControl}"
       BasedOn="{StaticResource {x:Type local:MetroTabControl}}">
    <Style.Resources>
         <SolidColorBrush x:Key="TabPanelBorderBrush" Color="Green"/>
    </Style.Resources>
</Style>