WPF WebBrowser inside a Popup - wpf

I want to have Popup with WebBrowser in it that appears when I click on window created with WinForms. I created user control that contains DockPanel with WebBrowser. I put this control in Popup and then when I click on window whole Popup appears except for WebBrowser. To check my control I put it directly to window - and it works. Is this problem because of mixing WPF and WinForms or WebBrowser just will not work in Popup?
MyControl
<DockPanel>
<WebBrowser Navigate="..." />
</DockPanel>
Popup
Popup foo = new Popup()
{
Child = MyControl
}
Event
void OnClick(object sender, EventArgs e)
{
foo.IsOpen = true;
}

Related

Create button to move WPF window

I have a borderless WPF window that I am using this answer to move at the moment: Move a borderless window in wpf
But I would really like to have have a button that when you click and hold lets you drag the window around. Is that possible?
Thank you.
Just attach a PreviewMouseDown event to the Button and use similar code
XAML
<Button PreviewMouseDown="Move" />
or CodeBehind
Button button = new Button();
button.PreviewMouseDown += Move;
Code
private void Move(object sender, RoutedEventArgs e)
{
// "window" is the name of the window
window.DragMove();
e.Handled = true;
}

How to click controls inside Popup with StaysOpen as False

I have a Popup with a ListView inside. I'd like to set StaysOpen as False so that it properly closes when I click away from the popup. However, this means that all mouse events are intercepted. As such, I don't get any mouse events inside my ListView.
Here's my current setup. I've removed all styling to make it easier to see what's going on.
<Popup Name="puSearchResults" StaysOpen="False"
AllowsTransparency="True"
LostFocus="puSearchResults_LostFocus"
LostKeyboardFocus="puSearchResults_LostKeyboardFocus"
LostMouseCapture="puSearchResults_LostMouseCapture" >
<ListView Name="lvSearchResults"
MouseLeftButtonDown="lbSearchResults_MouseLeftButtonDown"
SelectionChanged="lvSearchResults_SelectionChanged"/>
</Popup>
In this case, MouseLeftButtonDown only works if I set StaysOpen to True, but then the Popup doesn't disappear if I click away.
Ideas?
I would add mouse events to the ListView or to the objects in your ListView's data templete.
Then you could do this:
private void lvSearchResults_MouseEnter(object sender, MouseEventArgs e)
{
puSearchResults.StaysOpen = true;
}
private void lvSearchResults_MouseLeave(object sender, MouseEventArgs e)
{
puSearchResults.StaysOpen = false;
}
EDIT
Similar question that should help: Close Wpf Popup On click of item of its own control template

Dynamically create ContextMenu in Silverlight 5

I have just started to use Silverlight this few days.
Currently I have generated some panel dynamically in a canvas. Each panel will have a shared MouseLeftButtonUp event which will display a ContextMenu.
The problem now is when I click on a first panel, the ContextMenu is able to show but when I click on a second panel, the first ContextMenu shown up instead of the second. The second panel will show its ContextMenu only when I click another time on the second panel.
Below is my code to generate the panel and the context menu:
void generatePanel()
{
StackPanel panel = new StackPanel();
panel.MouseLeftButtonUp += panel_MouseLeftButtonUp;
canvas.Children.Add(panel)
}
void panel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
ContextMenu menu = new ContextMenu();
menu.IsOpen = true;
}
Hopefully my problem is clear enough. Is there any way to solve the problem? Or if there are any event that are fired when the menu is hidden, so that I can make sure the previous context menu is disposed or cleared?
Thanks.

Open an xaml file inside a popup window in silverlight

I need to open an xaml file inside a popup window in silverlight.
In my case i am having two xaml files namely a.axml and b.axml.,
In a.xaml, there is a hyper link button and a popup tag inside it.
I have to open the b.xaml page inside that popup window on clicking the hyperlink of the a.xaml page.
This is my scenario. Pls help me to solve this issue.
thanks,
Neon
You should be able to set the Child property of the popup to be a new instance of your b.xaml class (whatever that is).
Using Telerik controls its getting easier. But you may use second method.
On Blend I changed the template of Telerik's child window. It seems better now
HyperlinkButton link = new HyperlinkButton();
link.Click += (s, a) =>
{
//With telerik
RadWindow w = new RadWindow();
w.Content=new UserControl();
w.Show();
w.ShowDialog();//Swith light and avoid access oter controls
//Without Telerik
Popup p = new Popup();
p.Child = w.Content as UserControl;
p.IsOpen = true;
};
Parent Page XAML:
<HyperlinkButton Content="HyperlinkButton" Height="23" HorizontalAlignment="Left" Margin="150,111,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="100" Click="hyperlinkButton1_Click" />
Code Behind :
public ParentPage()
{
InitializeComponent();
}
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
{
ChildPage objpage = new ChildPage();
objpage.Show();
}
Here Is Pararent Page have buuton . child page load based on That button Click

ShowDialog makes app window disappear from windows' Alt-Tab list?

i am new to WPF, and i am trying to open a modal dialog from inside my main window:
public partial class MainWindow : Window
{
protected void OpenCommandExecuted(object target, ExecutedRoutedEventArgs e)
{
DataSearchWindow w = new DataSearchWindow();
w.Owner = this;
w.ShowDialog();
}
...
}
and XAML for my DataSearchWindow looks like this:
<Window x:Class="DataSearchWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShowInTaskbar='False'
WindowStartupLocation='CenterOwner'
WindowStyle='ToolWindow'
...>
...
</Window>
Everything works until I press Alt-Tab to switch to another application. When I do that my application disappears from the list shown when Alt-Tab is pressed. It is still in the taskbar and I can return to it using mouse, bu not with Alt-Tab. Has anyone seen this?
konstantin
This is because of the modal dialog - you cannot Alt-Tab back to the application until the dialog is closed. Since the WindowStyle is set as ToolWindow, it won't show up in Alt-Tab. However, if it were a regular window, the dialog window would show up in Alt-Tab.
Note that this isn't a WPF issue - it is consistent with, for example, a Windows Forms application.

Resources