Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The binding problem comes from the default style for ListBoxItem. By default when applying styles to elements WPF looks for the default styles and applies each property that is not specifically set in the custom style from the default style. Refer to <a href="http://www.interact-sw.co.uk/iangblog/2007/02/14/wpfdefaulttemplate" rel="nofollow noreferrer">this great blog post</a> By Ian Griffiths for more details on this behavior.</p> <p>Back to our problem. Here is the default style for ListBoxItem:</p> <pre><code>&lt;Style xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" TargetType="{x:Type ListBoxItem}"&gt; &lt;Style.Resources&gt; &lt;ResourceDictionary/&gt; &lt;/Style.Resources&gt; &lt;Setter Property="Panel.Background"&gt; &lt;Setter.Value&gt; &lt;SolidColorBrush&gt; #00FFFFFF &lt;/SolidColorBrush&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Control.HorizontalContentAlignment"&gt; &lt;Setter.Value&gt; &lt;Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}"/&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Control.VerticalContentAlignment"&gt; &lt;Setter.Value&gt; &lt;Binding Path="VerticalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}"/&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Control.Padding"&gt; &lt;Setter.Value&gt; &lt;Thickness&gt; 2,0,0,0 &lt;/Thickness&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Control.Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type ListBoxItem}"&gt; ... &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>Note that I have removed the ControlTemplate to make it compact (I have used <a href="https://github.com/drewnoakes/style-snooper" rel="nofollow noreferrer">StyleSnooper</a> - to retrieve the style). You can see that there is a binding with a relative source set to ancestor with type ItemsControl. So in your case the ListBoxItems that are created when binding did not find their ItemsControl. Can you provide more info with what is the ItemsSource for your ListBox?</p> <p>P.S.: One way to remove the errors is to create new setters for HorizontalContentAlignment and VerticalContentAlignment in your custom Style.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload