Search code examples
wpflistboxpopuptogglexceed

Popup doesn't bind to Toggle when inside DataGrid (xceed)


I've made a Toggle, which expands a Popup window with a ListBox inside. It looks like so:

<ToggleButton Name="Toggle" Height="20" Width="150" >
    <StackPanel>
        <TextBlock Text="TestListPopup"/>
        <Popup Height="200" Width="150"
                            IsOpen="{Binding ElementName=Toggle, Path=IsChecked}"
                            PlacementTarget="{Binding ElementName=Toggle}"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Bottom">
            <ListBox SelectionMode="Multiple" SelectionChanged="TypeSelectionChanged" >
                <ListBoxItem Content="Test1"/>
                <ListBoxItem Content="Test2"/>
                <ListBoxItem Content="Test3"/>
            </ListBox>
        </Popup>
    </StackPanel>
</ToggleButton>

It works perfectly, but I want to use it inside the FilterRow of my xceed DataGrid here:

<xcdg:DataGridControl x:Name="dataGrid"
                      ItemsSource="{Binding Source={StaticResource DataSource}}">
    <xcdg:DataGridControl.View>
        <xcdg:TableflowView>
            <xcdg:TableflowView.FixedHeaders>
                <DataTemplate>
                    <xcdg:ColumnManagerRow/>
                </DataTemplate>
                <DataTemplate>
                    <xcdg:FilterRow>
                        <xcdg:FilterCell FieldName="Name" IsEnabled="True"/>
                        <xcdg:FilterCell FieldName="Type" IsEnabled="True">
                            <!--  TestListPopup control here  -->
                        </xcdg:FilterCell>
                    </xcdg:FilterRow>
                </DataTemplate>
            </xcdg:TableflowView.FixedHeaders>
        </xcdg:TableflowView>
    </xcdg:DataGridControl.View>
    <xcdg:DataGridControl.Columns>
        <xcdg:Column FieldName="Name" Title="Name" />
        <xcdg:Column FieldName="Type" Title="Type" Width="160"/>
    </xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>

In here though, the popup will not bind to the toggle button. Pressing the toggle button doesn't do anything.

I narrowed it down to the binding being broken, because if you set IsOpen="True", it's open (and not adhering to PlacementTarget), but again; it works perfectly outside of the DataGrid..

Why does a perfectly functional control break once put inside the FilterRow?

Any help is appreciated! :)


Solution

  • Why does a perfectly functional control break once put inside the FilterRow?

    Because the ToggleButton and the FilterCell don't belong to the same namescope.

    You may try to bind using an x:Reference:

    IsOpen="{Binding Path=IsChecked, Source={x:Reference Toggle}}"
    

    The other option would be to bind the IsChecked property of the ToggleButton to a bool property of a view model and also bind the IsOpen property of the Popup to the same source property. Make sure that the view model implements the INotifyPropertyChanged interface and raise change notifications when the source property is set.