Attach Flyout to Listview - wpf

I have a Listview defined like this:
<ListView x:Name="lvPlaylist" Width="530" Height="337" IsItemClickEnabled="True" ItemClick="gvPlaylist_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Image Stretch="Fill" Source="{Binding albumArtURI}" Height="48" Width="48" />
<TextBlock Text="{Binding GetPlaylistFormat}" Width="500" Height="18"/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I want to open a "context"-Flyout on each Item on click.
So far I was only able to attach the flyout to the whole but then the flyout is shown at the border of the listview - not directly attached to the selected item.

Buttons have a Flyout property. All you have to do is wrap the contents of the template in a Button, create a Style for the button which removes all visuals for it, then create a Flyout for it.
<DataTemplate>
<Button Style="{StaticResource ButtonWrapperStyle}">
<Button.Content>
<Grid>
<Image Stretch="Fill" Source="{Binding albumArtURI}" Height="48" Width="48" />
<TextBlock Text="{Binding GetPlaylistFormat}" Width="500" Height="18"/>
</Grid>
</Button.Content>
<Button.Flyout>
<!-- Make Flyout Here -->
</Button.Flyout>
</Button>
</DataTemplate>
Obviously there is stuff left to do here, but you get the idea.
Hope this helps and happy coding!

Looks like you can also do it like this
From MSDN
"The next example shows a Flyout attached to a TextBlock. As noted earlier, you can attach a Flyout to any FrameworkElement by using the FlyoutBase.AttachedFlyout attached property."
<TextBlock Text="{Binding ElementName=MyTextBox, Path=Text}"
Tapped="TextBlock_Tapped" FontSize="18">
<FlyoutBase.AttachedFlyout>
<Flyout>
<TextBox x:Name="MyTextBox" Text="You can edit this text by tapping it."/>
</Flyout>
</FlyoutBase.AttachedFlyout>
</TextBlock>

Related

Border that bulges near mouse pointer

I have a ListView populated with ListViewItems, like navigation bar style menu options.
I would like to create the effect of the ListViewItem border "bulging" like in the Mail application on Win10 as shown in this picture
The border "bulges" (fisheye?) as the mouse moves left and right along the ListViewItem. It's a nice effect that I'd like to replicate but am struggling to even get started on how to tackle this.
My list items are bound to a content control which is templated with a ControlTemplate. The ItemsControl ItemTemplate is a DataTemplate containing an image and a Textbox wrapped inside a button control, like this .... (although I suspect how it's created is probably not relevant to my question)
<ContentControl Content="{Binding Path=MenuModel.AllMenuItems}"
x:Name="menuCtrl1"
Template="{StaticResource MenuListItemControlTemplate}"
VerticalAlignment="Top" />
...
<ControlTemplate x:Key="MenuListItemControlTemplate" TargetType="ContentControl">
<Border Background="Transparent" >
<ScrollViewer Margin="{StaticResource DefaultNoMargin}" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{TemplateBinding Content}"
ItemTemplate="{StaticResource MenuListItemDataTemplate}" />
</ScrollViewer>
</Border>
</ControlTemplate>
...
<DataTemplate x:Key="MenuListItemDataTemplate" DataType="local:SingleMenuItem">
<Button Command="{Binding MenuCommand}" Style="{StaticResource MenuButtonStyle}" >
<StackPanel Orientation="Horizontal" >
<Image Source="{Binding MenuIconSource}" Style="{StaticResource MenuItemImage}" />
<TextBox Text="{Binding DisplayText}" Style="{StaticResource MenuItemStyle}" />
</StackPanel>
</Button>
</DataTemplate>
Any tips on how to achieve it or even where to start would be gratefully received.

stackpanel containing button does not fire command wpf

I have a stackpanel that contains many elements including buttons. I am not able to fire a method through ICommands. It works through adding an event handler in the code behind for the Button.Click event. Since, I am following a MVVM pattern, I want to fire a command. Also, this stackpanel is a datatemplate for my listviewitem.
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" IsHitTestVisible="True">
<Button Cursor="Hand" Command="{Binding MoveImageUp}">
<Button.Background>
<ImageBrush ImageSource="..."/>
</Button.Background>
</Button>
<Grid>
<Image Source="{Binding Path=Image}"/>
<TextBlock Height="20" Width="20" Text="{Binding Path=Order}" Opacity="0.8" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
<GridSplitter HorizontalAlignment="Center" Padding="1" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
I have tried setting IsHitTestVisibile to true, does not work.
There was no DataContext set for the button. Thanks #Foggy Finder
<Button Cursor="Hand" Command="{Binding ElementName=ImagesList, Path=DataContext.MoveImageUp}" CommandParameter="{Binding}">

WPF Mouse Binding on Listbox Item Template Inconsistent

I have a listbox which binds to an observable collection of a custom type which displays each item through my data template:
<ListBox x:Name="ListBox" Style="{StaticResource CustomListBox}" ItemsSource="{Binding HandStats}" Height="410" Width="150" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding HoleCards[0].CardParts.Value}" Margin="2"/>
<Image Source="{Binding HoleCards[0].SuitImagePath}" Width="10" Height="10" Margin="2"/>
<TextBlock Text="{Binding HoleCards[1].CardParts.Value}" Margin="2"/>
<Image Source="{Binding HoleCards[1].SuitImagePath}" Width="10" Height="10" Margin="2"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Runs:" Margin="2"/>
<TextBlock Text="{Binding NumberOfRuns}" Margin="2"/>
<TextBlock Text="Players:" Margin="2"/>
<TextBlock Text="{Binding NumberOfPlayers}" Margin="2"/>
</StackPanel>
<StackPanel.InputBindings>
<MouseBinding Gesture="LeftClick" Command="{Binding Path=DataContext.PopulateReport, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
CommandParameter="{Binding ElementName=ListBox, Path=SelectedItem}"/>
</StackPanel.InputBindings>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Image of my listbox:
http://imgur.com/a/QGz8z
Now ideally when I click anywhere in the stack panel for each item, the item will be selected and the command will be fired. But my problem is that the item selection and the command firing is not working as it should.
The item will only become selected if I click in between the text blocks or in the empty space to the right of the text blocks, but the command will not be fired. The command will only fire once I have firstly selected the item, and then click again onto one of the text blocks or one of the images.
I'm still quite new to WPF so if I'm not making much sense please let me know, thanks in advance :)
So instead of using input bindings I decided to use a different method. I created a property in my vm and bound this to the selected item of my list. So now every time I select a new item (which works perfectly now) the property is updated in my vm. Simple!
Try to set the Background property of the StackPanel to Transparent:
<StackPanel Orientation="Vertical" Background="Transparent">
...
If it doesn't have a Background the click events won't be raised as expected.

WPF Popup inside a DataTemplate

I need a WPF Popup inside a DataTemplate, something like this:
<ScrollViewer>
<ItemsControl ItemsSource="{Binding Collection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBox Name="MyTextboxBrief" Text="{Binding TextBrief}"/>
<Popup PlacementTarget="{Binding ElementName=MyTextboxBrief}" Placement="Center">
<TextBox Name="MyTextboxVerbose" Text="{Binding TextVerbose}"/>
</Popup>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
But, this Popup should behave like this:
it must scroll together with relevant ItemsControl item
when app window is minimized - it shouldn't stay visible on desktop
it will be taller than ItemsControl, its content mustn't be clipped, but it mustn't change ItemsControl height
it will be wider than relevant ItemsControl item - but it shouldn't shift other ItemsControl items to the left or to the right
I have a strong feeling that I should somehow use ComboBox template - but I don't understand how to get it's Popup behavior
I don't think that Popup will help you here, nor ComboBox. See if this helps you any further:
<DataTemplate>
<Grid>
<TextBox Name="MyTextboxBrief" Text="{Binding TextBrief}" />
<!-- You might want to bind visibility against
some kind of property -->
<Canvas >
<Canvas.RenderTransform>
<!--In case you want to move-->
<TranslateTransform Y="-5" />
</Canvas.RenderTransform>
<Border Width="100" Height="20" Background="Black">
<TextBlock Text="Test" />
</Border>
</Canvas>
</Grid>
</DataTemplate>

Preloader/Progress Bar in ListBox WP7

I would like to add a preloader to a ListBox, I already added a preloader to the whole pivot control, but I only show it for one listbox (I have a listbox for each pivot page) I wish to create separate preloaders for each listbox, has any one done this?
I currently have a preloader control, showing the loading text and progress bar
Is there any way I can attach a progress bar to the listbox, and show it until the data is loaded from the webservice (For each different listbox)?
This is my current preloader:
code preview of my list in xaml
<telerikPrimitives:RadDataBoundListBox HorizontalAlignment="Left" Margin="4,0,0,0" Name="listNearbyBusinesses" IsAsyncBalanceEnabled="True" AsyncBalanceMode="FillViewportFirst" SelectionChanged="listNearbyBusinesses_SelectionChanged" Height="535" VerticalAlignment="Top" Grid.RowSpan="2" Grid.ColumnSpan="2">
<telerikPrimitives:RadDataBoundListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Width="100" Height="100" x:Name="m_Image" Source="{Binding Image}"/>
<StackPanel>
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" />
<TextBlock Text="{Binding Type}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}" />
<telerikInput:RadRating IsReadOnly="True" Value="{Binding Rating}" Margin="12" ItemShapeHeight="20" ItemShapeWidth="20" />
</StackPanel>
</StackPanel>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemTemplate>
</telerikPrimitives:RadDataBoundListBox>

Resources