How to get rid of annoying HorizontalContentAlignment binding warning?

Posted by marco.ragogna on Stack Overflow See other posts from Stack Overflow or by marco.ragogna
Published on 2010-04-19T10:00:17Z Indexed on 2010/04/19 10:03 UTC
Read the original article Hit count: 578

Filed under:
|
|
|

I am working on a large WPF project and during debug my output window is filled with these annoying warnings:

System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid > fallback value exists; using default instead. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name=''); target property is 'HorizontalContentAlignment' (type >' HorizontalAlignment')

In the specific example ComboBoxItem is styled in this way:

<Style x:Key="{x:Type ComboBoxItem}" TargetType="{x:Type ComboBoxItem}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>                  
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                <Border 
                    Name="bd"
                    Padding="4,4,4,4"
                    SnapsToDevicePixels="True" 
                    CornerRadius="2,2,2,2">
                    <ContentPresenter />
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsHighlighted" Value="true">
                        <Setter TargetName="bd" Property="Background"  Value="{StaticResource MediumBrush}"/>
                        <Setter TargetName="bd" Property="Padding"  Value="4,4,4,4"/>
                        <Setter TargetName="bd" Property="CornerRadius"  Value="2,2,2,2"/>
                    </Trigger>
                </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

I know that the problem is generated by the default theme definition for ComboBoxItem that contains things like:

<Setter Property="Control.HorizontalContentAlignment">
        <Setter.Value>
            <Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
            </Setter.Value>
        </Setter>

but I also thought that using

<Setter Property="OverridesDefaultStyle" Value="True"/> 

would taken care of the problem, and instead warnings are still there.

Any help is really appreciated

© Stack Overflow or respective owner

Related posts about .NET

Related posts about wpf