brighty.john
Topic Author
Posts: 3
Joined: 15 Apr 2021, 07:37

PreviewMouseDown Event not firing. [native sdk]

27 Apr 2021, 07:44

Hi, I have ListBox control whose item is a UserControl. The UserControl contains an Expander control whose style(includes content template) is set from code.
Here's the ListBox control :
       <Grid ClipToBounds="True">
            <ListBox x:Name="TrainingItemControl" 
                 ItemsSource="{Binding TrainingTiles}" 
                 ItemContainerStyle= "{Binding TrainingTileContentStyleBinding, 
                                        RelativeSource={RelativeSource AncestorType=UserControl}, 
                                        TargetNullValue={StaticResource TrainingTileContentStyle}, 
                                        FallbackValue={StaticResource TrainingTileContentStyle}}" 
                 Style="{StaticResource TrainingTileContentHolder}" 
                 SelectedItem="{Binding SelectedTrainingItem}" 
                 SelectedIndex="{Binding SelectedIndex}" Height="650" Width="750" 
                     HorizontalContentAlignment="Center"
                 ScrollViewer.CanContentScroll="False" ScrollViewer.HorizontalScrollBarVisibility="Hidden" />
        </Grid>
and the ItemContainerStyle is:
   <Style x:Key="TrainingTileContentStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                            <local:TileGeneric Type="{Binding TileType}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
TileGeneric contains :
<Grid x:Name="root" ForceCursor="False" Focusable="True" Height="600" >
        <Expander x:Name="ExportExpander" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" VerticalContentAlignment="Stretch" 
                  HorizontalContentAlignment="Stretch" ExpandDirection="Right" IsExpanded="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorLevel=1,
                                                                        AncestorType={x:Type ListBoxItem}},Path=IsSelected}"/>
    </Grid>
I would like to expand the Expander when I click on the ListBox item, but for some reason, the ListBox control and its contents are not capturing any mouse movements or clicks.
I tried using Interaction.Triggers and also tried raising the MouseDown event from code behind but nothing worked. Could you please tell me what might be the reason?

Tags:
 
KeldorKatarn
Posts: 193
Joined: 30 May 2014, 10:26

Re: PreviewMouseDown Event not firing. [native sdk]

27 Apr 2021, 17:26

I don't have the time right now to look at this in detail so I'm not sure if the Binding is 100% correct. What I do suggest as a general tip however is this:

Write yourself a ValueConverter that is called DebugConverter and basically just converts a value into itself. That gives you some code you can put a breakpoint into, so you can see what data arrives in your databinding.
That makes debugging bindings a lot less of a mess.
 
User avatar
sfernandez
Site Admin
Posts: 2255
Joined: 22 Dec 2011, 19:20

Re: PreviewMouseDown Event not firing. [native sdk]

27 Apr 2021, 21:42

Having a ListBoxItem that expands a Expander when it gets selected should work as you can see in the following xamltoy:

Is that what you are looking for?
 
brighty.john
Topic Author
Posts: 3
Joined: 15 Apr 2021, 07:37

Re: PreviewMouseDown Event not firing. [native sdk]

30 Apr 2021, 07:11

No, the ListBoxItem must be an UserControl as it is reused in other views. I tried your approach too. It did not work.
 
User avatar
sfernandez
Site Admin
Posts: 2255
Joined: 22 Dec 2011, 19:20

Re: PreviewMouseDown Event not firing. [native sdk]

30 Apr 2021, 20:02

No, the ListBoxItem must be an UserControl as it is reused in other views.
Using a UserControl to define the contents of the ListBoxItem is also possible, I just did a small test and it worked as expected.
I tried your approach too. It did not work.
I updated my previous XamlToy to show the SelectedItem of the ListBox. If you give it a try (click on the 'Run' button) you will see it gets updated when you expand the Expander control for any of the items.

Who is online

Users browsing this forum: Google [Bot] and 2 guests