- brighty.john
- Posts: 3
- Joined:
PreviewMouseDown Event not firing. [native sdk]
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 :
and the ItemContainerStyle is:
TileGeneric contains :
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?
Here's the ListBox control :
Code: Select all
<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>
Code: Select all
<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>
Code: Select all
<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 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?
- KeldorKatarn
- Posts: 193
- Joined:
Re: PreviewMouseDown Event not firing. [native sdk]
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.
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.
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: PreviewMouseDown Event not firing. [native sdk]
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?
Is that what you are looking for?
- brighty.john
- Posts: 3
- Joined:
Re: PreviewMouseDown Event not firing. [native sdk]
No, the ListBoxItem must be an UserControl as it is reused in other views. I tried your approach too. It did not work.
-
sfernandez
Site Admin
- Posts: 2997
- Joined:
Re: PreviewMouseDown Event not firing. [native sdk]
Using a UserControl to define the contents of the ListBoxItem is also possible, I just did a small test and it worked as expected.No, the ListBoxItem must be an UserControl as it is reused in other views.
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.I tried your approach too. It did not work.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 5 guests