我遇到了数据绑定问题。我有一个具有属性的类来自定义用wpf编写的样式。除ContentPresenter的投影颜色属性外,所有属性都可以正常工作。这是唯一没有用的属性。我尝试了很多东西,但没有任何案例。该属性称为FontShadow(类型为Color)
班级代码:
public class ButtonStyle
{
public String Name { get; set; }
public String Fill { get; set; }
public String FontColor { get; set; }
public Color FontShadow { get; set; }
public String Image { get; set; }
public int ImageWith { get; set; }
public int ImageHeight { get; set; }
public int FontSize { get; set; }
public String FontName { get; set; }
public Boolean Bold { get; set; }
public String HAligment { get; set; }
public String ButtonStyleName { get; set; }
}
xaml代码:
<Style x:Key="CommonActionButton" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
.....
<ContentPresenter DataContext="{TemplateBinding DataContext}" x:Name="contentPresenter" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Grid.RowSpan="2" RenderTransformOrigin="0.5,0.5">
<ContentPresenter.Effect>
<DropShadowEffect BlurRadius="3" ShadowDepth="2" Color="{Binding FontShadow, FallbackValue=Black}"/>
</ContentPresenter.Effect>
<ContentPresenter.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</ContentPresenter.RenderTransform>
</ContentPresenter>
.....
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
一个创建按钮我指定样式和de数据上下文(ButtonStyle的实例)。除FontShadow之外的每个属性都有效。
有什么想法吗?
答案 0 :(得分:1)
看一下这个问题:WPF Image 'highlight' with DropShadowEffect can't bind color
您应该为这种数据绑定设置DataContext。