0

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! :)

mm8
  • 163,881
  • 10
  • 57
  • 88
Hjalte Tagmose
  • 67
  • 1
  • 12

1 Answers1

1

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.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thank you! I knew there had to be a reasonable explanation. However the `x:Reference` solution puts the app into breakmode, with following error _Cannot call MarkupExtension.ProvideValue because of a cyclical dependency. Properties inside a MarkupExtension cannot reference objects that reference the result of the MarkupExtension_. The other solution isn't really gonna work for me either, because I might want multiple controls pr grid/view and I dont want a bunch of IsOpenX-vars. All that said you definitely gave me a big push in the right direction so thank you! :) – Hjalte Tagmose Nov 08 '18 at 13:14
  • Okay I found out what was happening. Apparently a child cannot `x:Reference` its parent, so I just put the Popup beside the Toggle instead of inside it! – Hjalte Tagmose Nov 08 '18 at 13:21