RadioButtonList generates binding warnings in debug window

WPF Studio, Themes, and Shared Library for WPF Forum

Posted 7 years ago by Jim Foye
Version: 12.2.0571
Platform: .NET 4.5
Environment: Windows 8 (64-bit)
Avatar

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ListBoxItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=VerticalContentAlignment; DataItem=null; target element is 'ListBoxItem' (Name=''); target property is 'VerticalContentAlignment' (type 'VerticalAlignment')

Here is my markup:

 

<Window x:Class="Chevron.Dpe.Presentation.Views.CustomUnitsView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:actipro="http://schemas.actiprosoftware.com/winfx/xaml/views"
        xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
        xmlns:views="clr-namespace:Chevron.Dpe.Presentation.Views"
        Title="Custom Units"
        Width="700"
        Height="450"
        WindowStartupLocation="CenterOwner">

    <DockPanel>
        <StackPanel Margin="3" HorizontalAlignment="Center" DockPanel.Dock="Bottom" Orientation="Horizontal">
            <Button Width="50" Margin="3" Click="OkClick" Content="OK" />
            <Button Width="50" Margin="3" Click="CancelClick" Content="Cancel" />
            <shared:PopupButton Width="105" Margin="3" Content="Default this to..." DisplayMode="Merged">
                <shared:PopupButton.PopupMenu>
                    <ContextMenu>
                        <MenuItem Command="{Binding Path=BaseOnCommand}" CommandParameter="Field" Header="Field" />
                        <MenuItem Command="{Binding Path=BaseOnCommand}" CommandParameter="Metric" Header="Metric" />
                        <MenuItem Command="{Binding Path=BaseOnCommand}" CommandParameter="Si" Header="Si" />
                    </ContextMenu>
                </shared:PopupButton.PopupMenu>
            </shared:PopupButton>
        </StackPanel>
        <Border Margin="3">
            <ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto">
                <ItemsControl BorderBrush="DarkSlateGray" BorderThickness=".5" ItemsSource="{Binding Path=DomainRows}">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <actipro:AnimatedWrapPanel />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Width="90" Margin="3" Padding="2" Text="{Binding Path=Description}" />
                                <shared:RadioButtonList Width="100"
                                                        Margin="3"
                                                        BorderBrush="#FF828790"
                                                        BorderThickness="1"
                                                        DisplayMemberPath="ShortName"
                                                        ItemsSource="{Binding Path=Units}"
                                                        SelectedItem="{Binding Path=SelectedUnit}" />
                            </StackPanel>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </ScrollViewer>
        </Border>
    </DockPanel>

</Window>

Comments (3)

Posted 7 years ago by Jim Foye
Avatar

In Snoop, I can see that the RadioButtonList uses ListBoxItem.

[Modified 7 years ago]

Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jim,

Sorry but I'm not sure offhand what's causing it.  RadioButtonList inherits ListBox and is pretty simple itself, just effectively giving another style to the items.  In our demo of the control we don't see it happening.  It could just be some sort of timing thing with your bindings, especially if everything is displaying properly.


Actipro Software Support

Posted 7 years ago by Jim Foye
Avatar

I am seeing this again, in a different project. I will email a video demonstrating it.

The binding errors refer to ListBoxItem, and a property being set in the default style, which points to the parent items control. Notice that the warnings only get emitted when I close the window.

If I point Snoop at the ListBoxItem, I can see that HorizontalContentAlignment is set correctly, via the style. If I leave the Snoop window open while I close my window, Snoop shows me that the binding gets broken somehow.

Jim

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.