i'm stuck with airspace problem. My WPF app hosts a winform component. I want to display a popup with some "waiting-please" text during component loading and long activities. Here I get my problem: popup is correctly display but when I handle component's busy event I cannot update popup content. Here some code XAML:
<WindowsFormsHost Name="wfh" Grid.Row="1" Grid.Column="0" ></WindowsFormsHost>
<Popup x:Name="Overlay" AllowsTransparency="True" Placement="Center"
StaysOpen="True"
IsOpen="True"
PlacementTarget="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid, AncestorLevel=1}}">
<TextBlock Name="tbWait" Foreground="Red" />
</Popup>
and c#:
myWinformComponent.Event => (s, e) =>
{
tbWait.Text = e.IsBusy ? "Loading..." : string.Empty;
}
I know what is the Airspace problem with WinForm and WPF but I was supposed that keep the popup always open let me display any content ove the windowformshost.
EDIT: I'm placing some breakpoints into the code behind and I see the Text property change correctly. This changes are not display into the UI.
Have you any workaround or solution?
Thank you guys!
According with #HansPassant comment, I can force redraw with these lines:
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(delegate(object parameter) {
frame.Continue = false;
return null;
}), null);
Dispatcher.PushFrame(frame);
Maybe it's not the most elegant solution, but it's a working patch to my issue.
Unfortunately, you can't display any WPF content over a WindowsFormsHost. I spent a long time fighting this quirk myself, until I finally gave up and rearraged the UI to make the overlay not have to be over the WinForms component.
Related
Hey I use the RDPCOMAPILib to shadow screens between two computers.
I added a windows forms user control to my project which include the axRDPViewer.
This Control is added to my WPF View in a windowsFormsHost control and works fine, see code:
<Grid Name="RDP">
<Border BorderBrush="Black" BorderThickness="2">
<WindowsFormsHost MouseDown="host_MouseDown" PreviewMouseDown="host_PreviewMouseDown" x:Name="host">
<controls:RDPViewer Click="viewer_Click" MouseClick="viewer_MouseClick" x:Name="viewer"/>
</WindowsFormsHost>
</Border>
</Grid>
But none of the click events is raised when I click on the control, but I don't know why?
I want to do something when I doubleclick on the control.
Hope somebody knows a solution to my problem.
I don't know anything about the library or control you're using, but you seem to be missing a " in the code you posted. You have
MouseClick="viewer_MouseClick x:Name="viewer"
but it should be
MouseClick="viewer_MouseClick" x:Name="viewer"
Is there a way to disable dropping items like notepad, word etc on to a System.Windows.Controls.WebBrowser control in WPF.
I have tried various options like
AllowDrop="False" - Does not work.
Tried to catch events like Drop, PreviewDrop, DragLeave, PreviewDragLeave, PreviewDragOver, PreviewDragEnter - None of these events fire when I drop items on the WebBrowser control.
Using the constructor or Xaml to create the following method will stop the drag from changing the webbrowsers current state:
private void webBrowser_Navigating(object sender, NavigatingCancelEventArgs e)
{
// The WebBrowser control is checking the Uri
if (e.Uri.ToString() != "Place your url string here") //ex: "http://stackoverflow.com"
{
// Uri is not the same so it cancels the process
e.Cancel = true;
}
}
As you mentioned, none of the Drop event are fired, and it seems like the native browser control is very limited which leaves you with two possibilities:
Either user another browser control like wpfchromium,
Or define a transparent popup in top of the browser and handle
the drop even within it
:
<WebBrowser Height="300" Width="300" x:Name="wbBrowser"/>
<Popup Opacity="1" AllowsTransparency="True" IsOpen="True" Placement="Center"
PlacementTarget="{Binding ElementName=wbBrowser}" >
<Border Background="Black" Opacity="0.01"
Width="300" Height="300">
</Border>
</Popup>
This solution ain't pretty at all and needs also more logic to handle when the popup's parent control moves..
...you may also find this solution helpful, if your main content is html:
How to disable drop on wpf webbrowser control
I am having a problem with a page in my Windows 8.1 Store App that is taking a long time to render - it is a grid with a number of columns and rows that gets bound to data on loading of the page.
It is not the loading of the data that is slow but the actual binding of the data to the grid.
I ideally want to display a dialog bar to indicate to the user that something is loading and they have clicked on the previous navigate button okay.
I saw someone mention the possibility of having a "loading page" which only has a progress bar in it - and I thought this solution might work but I can't work out in what event of the loading page should I navigate to the actual page.
i.e.
User clicks button which calls
this.Frame.Navigate(typeof(LoadingPage));
Loading Page displays a progress bar
I know need to be able to call
this.Frame.Navigate(typeof(ActualPage));
The user sees the progress bar whilst ActualPage loads.
Any suggestions would be greatly appreciated thanks!
Thanks to the support team at DEVExpress I have a solution to my problem.
Firstly on the page that takes time to load I have wrapped my Grid in a ContentControl
<ContentControl Visibility="Collapsed" Name="Content">
<!-- Grid in here -->
</ContentControl>
I then added a TextBlock which I will use as to display "Loading..." to my page. I have called this control indicator.
<TextBlock x:Name="indicator" Text="Loading..." />
I have attached the following method to the Loaded event of the page which uses a timer
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
indicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
DispatcherTimer t = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };
t.Tick += (dd, ee) =>
{
t.Stop();
Content.Visibility = Windows.UI.Xaml.Visibility.Visible;
};
t.Start();
}
Then when the gridcontrol has Loaded I hide the indicator TextBlock
void gridControl_Loaded(object sender, RoutedEventArgs e)
{
indicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
This works perfectly for me. I can't use the Windows 8 ProgressBar control because the animation is loaded on the same thread that loads the grid - but I am happy enough to have any indicator.
Also thanks Brian Stump for pointing me in the right direction.
First, I will suggest using a ListView or GridView to display your databound objects because of build-in UI virtualization.
However, maybe this will work for your situation.
Do you know when your page is ready to display? If so, place a progress ring in front of your grid while it loads in the background.
<Grid x:Name="FullPageGrid">
<Grid x:Name="YourGridContent">
</Grid>
<Grid Background="White" Visibility="Visible" x:Name="ProgressRingGrid">
<ProgressRing IsActive="True"></ProgressRing>
</Grid>
</Grid>
When the data is fully loaded, change the visibility of the "ProgressRingGrid" to Visibility="Collapsed"
I have a textbox with a button inside (Telerik's RadTextBox with an Action configured).
When the user presses the Action, a progress bas is displayed, the screen goes dark, and some magic happens.
My problem is that since the action doesn't result in the textbox losing focus, the on-screen keyboard is not hidden, and keeps covering half the screen.
I would like to programmatically hide the on-screen keyboard, but don't know how.
Just set focus to the main page:
this.Focus();
this will focus a control that doesn't use the keyboard and thus hide the keyboard. Unfortunately there is no API to the keyboard to hide it.
Instead try disabling and then enabling the textbox in question in an appropriate place (like once a query has been submitted or an action triggered):
TextBox.IsEnabled = false;
TextBox.IsEnabled = true;
(Via https://stackoverflow.com/a/23905874/1963978)
Not clean, but it does the job (in Windows 10 mobile).
here lot solution is available for a Textblock only but in my case AutoCompleteBox
<toolkit:AutoCompleteBox Name="autoComplateTxt"
Grid.Row="4"
Margin="15,5,2,10"
Padding="0"
Height="65"
Text=""
BorderThickness="1"
BorderBrush="Black"
VerticalAlignment="Center"
DropDownClosed="autoComplateTxt_DropDownClosed"
/>
private void autoComplateTxt_DropDownClosed(object sender, RoutedPropertyChangedEventArgs<bool> e)
{
this.Focus();
}
I have WP7 application with several pages. When a user navigates through them it takes some time to load information. So before showing him/her the page I'd like to show “Loading…” message.
I created progress bar and placed it on the page:
<StackPanel x:Name="progressBarMain" Grid.Row="1" Grid.ColumnSpan="2" Visibility="Collapsed">
<TextBlock Text="Loading..." HorizontalAlignment="Center" VerticalAlignment="Center" />
<ProgressBar Margin="10" Height="30" IsIndeterminate="True"/>
</StackPanel>
And I'm trying to show it (and hide everything else) in the page's constructor, and hide it (and show everything else) in Page.Loaded handler.
public SomePage()
{
InitializeComponent();
Loaded +=OnSomePageLoaded;
progressBarMain.Visibility = Visibility.Visible;
ContentPanel.Visibility = Visibility.Collapsed;
}
private void OnSomePageLoaded(object sender, RoutedEventArgs e)
{
progressBarMain.Visibility = Visibility.Collapsed;
ContentPanel.Visibility = Visibility.Visible;
}
But it doesn’t' work.
Any ideas? Thank you!
Alex demonstrates showing a progress bar while the app is starting up here.
Creating a Splash Screen with a progress bar for WP7 applications. - Alex Yakhnin's Blog
Although you cannot directly manipulate the splash screen (which is static), you can display a popup (by the way, that is exactly what is done in Alex's solution) and wait for a background (read: loading) operation to complete.
Yes, you'll need to create a separate XAML Pop-up page that is loaded when the app boots up. For more details on Splash Screens, there is a code sample from MSDN:
"Code Sample for Splash Screen"