Silverlight Remove Popup Control from Visual Tree - silverlight

I have a silverlight application, with a control (kind of tooltip) inside a popup, and want to remove this popup in certain case.
In silverlight spy I see that this popup is not a child element of the rootvisual, but appears at the same level.
How can I remove this Popup?
Thanks

OK, So I managed to solve this issue, and it was fairly easy at last.
This is the code I used:
var popups = VisualTreeHelper.GetOpenPopups();
foreach (Popup pop in popups)
{
if (pop != null && pop.Child is ToolTip)
{
((ToolTip)pop.Child).IsOpen = false;
}
}

Related

wpf Popup Lightbox effect on window

I am using following code to set gray light effect on window when I open a popup. It works fine but it basically reloads all controls or refreshes the main window .
Especially this line: currentWindow.Content = lightboxGrid;
Window currentWindow = Application.Current.Windows.Cast<Window>()
.SingleOrDefault(x => x.Name.Equals(MAIN_WINDOW_NAME));
Grid lightboxGrid = new Grid();
object currentWindowContent = currentWindow.Content;
currentWindow.Content = null;
lightboxGrid.Children.Add(new ContentControl()
{
Content = currentWindowContent
});
// now add the grid that will "black out" the content
Grid blackoutGrid = new Grid();
blackoutGrid.Background = new SolidColorBrush(Colors.Black);
lightboxGrid.Children.Add(blackoutGrid);
blackoutGrid.Opacity = 0.0; // start fully transparent
blackoutGrid.Loaded += blackoutGrid_Loaded;
currentWindow.Content = lightboxGrid;
this._lightboxEffectApplied = true;
What could be the option to have the same effect without refreshing the main window or reloading the controls?
If your main window has a Grid as its layout root (even if all the content is in the first cell), then you could add this blackoutGrid as a child to that grid and it will display above the other elements without messing with the original visual tree structure.
In this case, the Content of your Window would be a Grid, and you would add your blackoutGrid to that Grid, and remove it when you are done.
The way you are writing this seems to be a little against object-oriented practice. Technically it should be your Main Window that has the ability to display a lightbox effect.

WebView is always the topmost component

I'm developing a reporting dashboard application using W8 Metro UI style application. The application has a dark theme, so most of the screen is black. I'm using the WebView control to display SSRS .rdl reports from our report server (which all have black backgrounds). The problem I'm seeing is that when I navigate to a new report, the WebView control flashes white for a split second and then loads the new report. To get around this, I tried putting an Easing opacity animation on the WebView control to make it fade out, load the report, and then fade back in. However, no matter what I try, I can't get the flickering to go away.
I then tried putting a black rectangle on top of the WebView and fading that one in and out... still no luck. The WebView is always on top at runtime, meaning I can't put any control on top of it. Does anyone know of a way around this?
I breifly looked into the WebView.Transitions, but couldn't find many resources on this. Could this be my answer?
EDIT:
Event to load the new report:
void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// Create a WebViewBrush of the content currently loaded in the WebView
WebViewBrush b = new WebViewBrush();
b.SourceName = "WebView1";
b.Redraw();
Rectangle1.Fill = b;
// Hide the WebView
WebView1.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
// Navigate to the new report
var selectedItem = ItemListView.SelectedItem;
WebView1.Navigate(((Report)selectedItem).ReportUri);
}
void WebView1_LoadCompleted(object sender, Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
// Show the new report
WebView1.Visibility = Windows.UI.Xaml.Visibility.Visible;
Rectangle1.Fill = new SolidColorBrush(Colors.Transparent);
}
This is just the way WebView works because internally its loading the trident COM control into a separate hwnd. The workaround is to set Visibility to Hidden on the webview and instead show a webviewbrush which isn't interactive but does integrate with the rest of your UI so it can be animated, etc

how to remove scrollbar after datastore removed?

i have a window with grid panel as the content...
when the window first shown, my store is empty and i can't see the scrorllbar (good)
when i load the data to store, i can see the scrollbar (good)
when i remove all data from store, i can still see the scrollbar and scrollable. when exactly there's no data in view (bad)
so my question is my title, how to remove scrollbar after datastore removed
here is the demo
Its is a open bug. Sencha team promises to fix it it 4.0.7. Have a look at this discussion at Sencha forum.
One possible solution given in the forum, is to hide the scrollbar using hideVerticalScroller() method. I did try it on fiddle but was not successful 100% (may be something to do with fiddle). I had to click "remove data" button twice to remove the scroll bar:
handler:function(){
storeSr.removeAll();
gridSr.hideVerticalScroller();
}
On the forum, they suggest doing (And this works!):
storeSr.removeAll();
var data = [];
var store = gridSr.getStore();
store.loadData(data, false);
if (data.length == 0) {
gridSr.hideVerticalScroller();
}

How can I progmatically click a link in a Winform Web Browser control?

I would like to know how to programatically click a link from with in a Winform Web Browser control.
foreach (HtmlElement linkElement in webBrowser.Document.GetElementsByTagName("A"))
{
if(linkElement.InnerText == "Helpful Tips")
{
//Click Functionality
}
You should be able to do this using the InvokeMember method. Something along these lines:
linkElement.InvokeMember("Click")

Nesting an Accordian Control has Problems Resizing Content

I am working on a site where I have an accordian control for the main content and in each is another accordian control. It worked fine so long as there were just a few items in there but once I got enough items in the child accordian they are clipped when expanding an item. It's not so bad for items near the top of the list but for items near the end you cannot see anything because it's completely clipped.
You can see them if you collapse the main accordian control and then expand it again. (see http://www.utahcodecamp.com/#Sessions/ to see what I mean)
Any suggestions? Can I force the parent accordian item to re-calculate the size?
It looks like you may have found a bug in the Accordian implementation. You should create a very small spike with just enough in it to reproduce the problem and post it to the issues section for the Silverlight Toolkit.
I found a work-around. It works perfectly!
"a" is the inner accordian.
void a_SizeChanged(object sender, SizeChangedEventArgs e)
{
var accordian = sender as AccordionItem;
var items = accordian.GetVisualAncestors();
foreach (DependencyObject obj in items)
{
if (obj is ExpandableContentControl)
{
ExpandableContentControl ctrl = obj as ExpandableContentControl;
ctrl.Height += e.NewSize.Height - e.PreviousSize.Height;
}
}
}

Resources