WPF Datagrid Popup Placement - wpf

I am showing a Popup when users double click a DataGrid row, is there a way to show this popup at the right of the SelectedItem?
Here is my current code:
<Popup PlacementTarget="{Binding ElementName=dgWarnings}" Placement="Right" Name="InfoPopup" PopupAnimation="Slide" AllowsTransparency="True" IsOpen="{Binding ShowInfo}">
I obviously cannot bind to the selected item property as this is not a UI item.
As I mentioned I would like to display it on the right hand side of the currently selected item in the datagrid.
Any suggestions?

Related

WPF: How to open User Control Popup on Fixed Position

I made a button wrapper around a UserControl, so that it operates as a button. When pressed, a popup screen is visible. However I want the popup screen to be a fixed location: For example upper right side of the UI.
Within this example the popup appears right on top of the UserControl.
<Popup IsOpen="{Binding IsChecked, ElementName=button}" x:Name="OpenPopup_FFU" StaysOpen="False" PlacementTarget="{Binding ElementName=button}">
<popup:Popup_FFU Height="500" Width="300"/>
</Popup>

How can I close a popup in WPF from inside its user control

I have implemented a toggle button with a popup similar to what is described here. My popup displays a user control that is basically a custom menu with several images/buttons on it. Here is the code for my toggle button:
<ToggleButton x:Name="btnMenu" Background="Transparent" HorizontalAlignment="Right">
<StackPanel>
<Image Width="60" Height="60" Margin="10,0,10,0" Source="{StaticResource icon-menu}"/>
<Popup StaysOpen="False" IsOpen="{Binding IsChecked, ElementName=btnMenu}" Placement="Bottom">
<controls:Menu/>
</Popup>
</StackPanel>
</ToggleButton>
Everything works fine, except that when I click on a button (which is bound to a command) in my user control, I would like the popup to disappear. Is there a way, through xaml, that I can close the parent popup when a button on the user control is pressed?
I did manage to find solutions on codeproject which would most likely solve the problem, and I also found various solutions on StackOverflow where all the xaml was inside the popup instead of a separate user control. I wanted to see if there was another preferred method (hopefully xaml based) that could solve this particular problem, and still let me keep my menu in a separate user control.

How to lock focus on popup in wpf

Is there any way in WPF to lock the focus on the popup so that we cannot set focus on other elements on the view?
I have a popup and have bound it to the IsOpen property of the ViewModel:
<Popup x:Name="myPopup"
Width="{Binding ElementName=RootLayout, Path=ActualWidth}"
Height="350"
PlacementTarget="{Binding ElementName=RootLayout}"
Placement="Center"
IsOpen="{Binding IsOpen}"
StaysOpen="True"
AllowsTransparency="True">
/// Popup elements
</Popup>
It works fine and when the IsOpen property in the ViewModel is set to true the popup shows up. but the problem is when I press the tab button, the focus goes to the other elements on the view while I need it to say on the popup.
How can I do that please? any help is appreciated.

How to open pop-up from link button and close it using button inside the pop-up?

I have main window, containing grid with different user controls. Each control is defined in separate Xaml. Then in MainWindow.xaml i match all particles of my main window.
One of my userControls is a menu, containing buttons.
i want to call popup after clicking some button in menu. Popup will contain some text, buttons and will overlay the main window.
So the question is how to call pop-up from menu-button and close it from button located on pop-up?
Thanks!
You can put a togglebutton in your menu, then bind the IsOpen property of the Popup to the IsChecked property of the togglebutton.
<ToggleButton x:Name="toggle" Content="ToggleButton" HorizontalAlignment="Left" Height="68" Margin="78,104,0,0" VerticalAlignment="Top" Width="102"/>
<Popup IsOpen="{Binding ElementName=toggle, Path=IsChecked}" StaysOpen="False">
<Grid Background="#FFE5E5E5" Height="299" Width="269">
<ToggleButton IsChecked="{Binding ElementName=toggle, Path=IsChecked}" Content="Close" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/>
</Grid>
</Popup>
Change StaysOpen back to True (the default) if you don't want the popup to go away when you click off it. In this situation, the togglebutton inside the popup will look a bit strange by default, but you can style it to look better.
If not all your code is in the same Xaml file, instead of binding by ElementName, you can bind them all to a boolean property in your viewmodel.

XAML ContextMenu gets bound to wrong row in a DataGrid

I have a XAML based ContextMenu bound to the rows in a datagrid. It works just fine - until the grid is scrolled!
This is the context menu for one of the controls in the visual tree or a DataGrid row.
<data:DataGridTemplateColumn Header="Customer Details" Width="*">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid Background="Transparent"> <!-- allows click in entire cell -->
<controlsInputToolkit:ContextMenuService.ContextMenu>
<controlsInputToolkit:ContextMenu>
<controlsInputToolkit:MenuItem Header="{Binding CompletedOrderId,StringFormat='Create Reminder for order #\{0\}'}"
CommandParameter="{Binding}">
<controlsInputToolkit:MenuItem.Command>
<command:CreateReminderCommand/>
</controlsInputToolkit:MenuItem.Command>
<controlsInputToolkit:MenuItem.Icon>
<Viewbox>
<Image Width="19" Height="18" Source="../images/reminders.png" VerticalAlignment="Center"/>
</Viewbox>
</controlsInputToolkit:MenuItem.Icon>
</controlsInputToolkit:MenuItem>
<controlsInputToolkit:ContextMenu>
<controlsInputToolkit:ContextMenuService.ContextMenu>
......
The ICommand is CreateReminderCommand and the CommandParameter is bound to the data item for the row itself.
This works just fine - I can right click on a row and it will show me the correct text in the menu item 'Create Reminder for order 12345'.
Then I scroll the datagrid down a page. If I keep right clicking on items then suddenly I'll see the wrong order number for a row. I think what must be happening is this :
The DataGrid is reusing instances of MenuItem that it has previously created.
How can I force a refresh of the ContextMenu when it is displayed for an item that changes? There's no 'Update method on the ContextMenu or ContextMenuService.
This turned out to be a Silverlight bug related to element binding.
http://blogs.msdn.com/delay/archive/2010/05/11/we-ve-secretly-changed-this-control-s-datacontext-let-s-see-if-it-notices-workaround-for-a-silverlight-data-binding-bug-affecting-various-scenarios-including-datagrid-contextmenu.aspx
The solution provided here fixes the problem.

Resources