I have a problem with a databinding. I have a class with properties to customize a style written with wpf. All properties works fine, except for the drop shadow color property from ContentPresenter. that is the only property that didn't work. I've tried a lot of things but no case. The property is called FontShadow ( type Color )
class code:
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; }
}
the xaml code:
<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>
one a create a button i assign the style and the de data context (instance of ButtonStyle). Every property except FontShadow works.
Any idea?
Have a look at this question: WPF Image 'highlight' with DropShadowEffect can't bind color
You should set the DataContext for this kind of databinding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With