问题描述
<Stylex:Key="JP_DataGridColumnHeader"TargetType="Primitives:DataGridColumnHeader"><SetterProperty="Foreground"Value="Black"/><SetterProperty="HorizontalContentAlignment"Value="Center"/><SetterProperty="VerticalContentAlignment"Value="Center"/><SetterProperty="FontSize"Value="10.5"/><SetterProperty="FontWeight"Value="Bold"/><SetterProperty="IsTabStop"Value="False"/><SetterProperty="SeparatorBrush"Value="#FFDFE3E6"/><SetterProperty="Padding"Value="4,4,5,4"/><SetterProperty="FontWeight"Value="Bold"></Setter><SetterProperty="Template"><Setter.Value><ControlTemplate><Gridx:Name="Root"><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinitionWidth="Auto"/></Grid.ColumnDefinitions><VisualStateManager.VisualStateGroups><VisualStateGroupx:Name="CommonStates"><VisualStatex:Name="Normal"/><VisualStatex:Name="MouseOver"><Storyboard><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundRectangle"Storyboard.TargetProperty="(Fill).Color"To="#FF448DCA"/><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundGradient"Storyboard.TargetProperty="(Fill).(GradientStops)[3].Color"To="#7FFFFFFF"/><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundGradient"Storyboard.TargetProperty="(Fill).(GradientStops)[2].Color"To="#CCFFFFFF"/><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundGradient"Storyboard.TargetProperty="(Fill).(GradientStops)[1].Color"To="#F2FFFFFF"/></Storyboard></VisualState><VisualStatex:Name="Pressed"><Storyboard><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundRectangle"Storyboard.TargetProperty="(Fill).Color"To="#FF448DCA"/><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundGradient"Storyboard.TargetProperty="(Fill).(GradientStops)[0].Color"To="#D8FFFFFF"/><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundGradient"Storyboard.TargetProperty="(Fill).(GradientStops)[1].Color"To="#C6FFFFFF"/><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundGradient"Storyboard.TargetProperty="(Fill).(GradientStops)[2].Color"To="#8CFFFFFF"/><ColorAnimationDuration="0"Storyboard.TargetName="BackgroundGradient"Storyboard.TargetProperty="(Fill).(GradientStops)[3].Color"To="#3FFFFFFF"/></Storyboard></VisualState></VisualStateGroup><VisualStateGroupx:Name="SortStates"><VisualStatex:Name="Unsorted"/><VisualStatex:Name="SortAscending"/><VisualStatex:Name="SortDescending"/></VisualStateGroup></VisualStateManager.VisualStateGroups><Rectanglex:Name="BackgroundRectangle"Fill="#FF1F3B53"Stretch="Fill"Grid.ColumnSpan="2"/><Rectanglex:Name="BackgroundGradient"Stretch="Fill"Grid.ColumnSpan="2"><Rectangle.Fill><LinearGradientBrushEndPoint=".7,1"StartPoint=".7,0"><GradientStopColor="#FCFFFFFF"Offset="0.015"/><GradientStopColor="#F7FFFFFF"Offset="0.375"/><GradientStopColor="#E5FFFFFF"Offset="0.6"/><GradientStopColor="#D1FFFFFF"Offset="1"/></LinearGradientBrush></Rectangle.Fill></Rectangle><GridHorizontalAlignment="{TemplateBindingHorizontalContentAlignment}"VerticalAlignment="{TemplateBindingVerticalContentAlignment}"></Grid><ContentPresenterVerticalAlignment="Center"Margin="3"HorizontalAlignment="Center"/><Rectanglex:Name="VerticalSeparator"Fill="#FFC9CACA"VerticalAlignment="Stretch"Width="1"Visibility="Visible"Grid.Row="1"Grid.Column="1"/></Grid></ControlTemplate></Setter.Value></Setter></Style>
为什么给这个样式加上Key之后只能在前台用HeaderStyle调用?领导是让我重新封装成一份新的自定义控件,但是我在后台用column1.HeaderStyle=Application.Current.Resources["JP_DataGridColumnHeader"]asStyle;
调用时根本无法调用?研究大半天了没弄出个结果,求大神帮忙啊
解决方案
解决方案二:
你绑定的时候,可能得使用DynamicResource。
解决方案三:
引用1楼lincolnandlinda的回复:
你绑定的时候,可能得使用DynamicResource。
啥意思?我尝试过各种办法去绑定样式,除非给设置成全局的,只要加上key我在后台就绑定不了求帮助啊