I have a ModernTab control, to which I'm dynamically adding a Link:
InstallationTab.Links.Add(new Link { DisplayName = "Review Configuration", Source = new Uri("/Views/InstallationProgress.xaml", UriKind.Relative) });
I'd like InstallationProgress.xaml to load in the top frame instead of the current content frame.
How can I do this?
I answered my own question, in case anyone else finds themselves here:
This is just one example of "hijacking" the click on the ModernTab. Here, you can force the content to load in the top frame, for example:
Handle the SelectedSourceChanged event of the ModernTab:
MyModernTab.SelectedSourceChanged += MyModernTab_SelectedSourceChanged;
void MyModernTab_SelectedSourceChanged(object sender, SourceEventArgs e)
{
if (e.Source.OriginalString.EndsWith("Foo.xaml"))
{
var url = "/Pages/Foo.xaml";
var bb = new BBCodeBlock();
bb.LinkNavigator.Navigate(new Uri(url, UriKind.Relative), this, NavigationHelper.FrameTop);
}
}
Related
In my website, in order to load diferent pages (to be multipage website) I have a main panel that has the id 'content-panel'.
When I want to load a diferent page I have a javascript function that is called 'loadPage' that loads the page (panel) that I want to the 'content-panel'.
But the page that I want to load has to have this code:
Ext.require(['*']);
Ext.onReady(function() {
...
var panel = Ext.Cmp('content-panel');
panel.add(loginPanel);
panel.layout.setActiveItem(loginPanel);
panel.doLayout();
panel.setLoading(false);
});
In this case it is loading the page/panel that is loginPanel, that is defined inside Ext.onReady
For me this is fine, I don't know of any other way of my website being multi-page.
But everytime that I want to go to a page it loads that page to the 'content-panel', even if it already been loaded before. I want a way to only add the page to 'content-panel' if it is not inside 'content-panel' items.
UPDATE:
Here is the loadPage
function swap(parent, replacement, url) {
var alpha = document.querySelector(parent);
var target = alpha.childNodes[0];
var omega = document.createElement(replacement);
omega.src = url;
omega.type = 'text/javascript';
alpha.replaceChild(omega, target);
}
function loadPage(panel, toPanel) {
toPanel.setLoading(true);
swap('head', 'script', panel);
}
it is used like this: loadPage('Ctl_base/view_admin/mainPage', Ext.getCmp('panel'));
I'm using CodeIgniter with ExtJS.
What I have already tried:
I want to do panel.add(loginPanel) only if the loginPanel doesn't exist.
I have tried:
if(panel.getComponent(loginScreen) == undefined) { panel.add(loginPanel); }
and it adds the component even when panel already has that component.
I have also tried:
function hasComponent(parent, child) {
parent.items.items.forEach(function(item) {
if(item == child){
return true;
}
});
return false;
}
if(!hasComponent(panel, loginPanel)) { panel.add(loginPanel); }
and it also doesn't work.
I have manage to tackle this question by putting and itemId on the panel that I want to load, and on panel.layout.setActiveItem(loginPanel); I have put panel.layout.setActiveItem('itemIdOfPanel');
I created thumbnails based on ListView control. On ListView.ItemSource I bind ObservableColletion<Photos> Photos{get;set}.
I create thumbnail images in another threads also in parallel way.
I simplified my code.
public class ThumbnailCreator
{
public static List<Photos> CreateThumbnailImage(List<Photos> photos)
{
var thumbnails = new List<Photos>();
Parallel.ForEach(photos, photo =>
{
var bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.DecodePixelHeight = 128;
bitmap.DecodePixelWidth = 128;
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.CreateOptions = BitmapCreateOptions.DelayCreation;
bitmap.UriSource = new Uri(photo.FullPath);
bitmap.EndInit();
if (bitmap.CanFreeze)
bitmap.Freeze();
thumbnails.Add(new Photos{ThumbnailImage = bitmap});
});
return thumbnails;
}
}
Problem is here:
//I break binding before I start refreshing thumbnails
this.Thumbnails.ItemsSource = null;
//load files from folder
List<Photos> photos = _fileManager.LoadFromDir(folderBrowserDialog.SelectedPath);
//create thumbnail images in another threads, not on UI
List<Photos> thumbnails = ThumbnailCreator.CreateThumbnailImage(photos);
//create new source
Photos = new ObservableCollection<Photos>(thumbnails);
//reenable binding, this part of code cause that UI free
this.Thumbnails.ItemsSource = Photos;
When I reenable binding UI freeze, I tried use dispatcher but result is same UI freeze.
this.Dispatcher.Invoke(DispatcherPriority.SystemIdle, new Action(() =>
{
Photos = new ObservableCollection<Photos>(thumbnails);
this.Thumbnails.ItemsSource = Photos;
}));
How can I avoid freeze UI?
EDITED:
I edited my code based on Dean K. advice. I dont break bind before update source of listview.
I updated source of ListView.ItemSource via Dispatcher:
Sync Invoke:
App.Current.Dispatcher.Invoke(new Action(() =>
{
thumbnails.Add(new Photos { ThumbnailImage = bitmap });
}), DispatcherPriority.ContextIdle);
Result - UI behavior.
Images are being added continuously but if collection contains more than 500 images at the and WPF window freezes. For example it is not possible move window, scroll listview.
Async Invoke
App.Current.Dispatcher.InvokeAsync(new Action(() =>
{
thumbnails.Add(new Photos { ThumbnailImage = bitmap });
}), DispatcherPriority.ContextIdle);
Result - UI behavior.
At start app freezes but after several seconds images are being added continously and also is it possible move window, scroll listview.
So my question is what is root of problem that app freezes ? How can I avoid this behaviour. I upload sample application.
Don't break the binding before adding items to the ObservableCollection.
Bind Thumbnails.ItemsSource to Photos OC and than on another thread load and add items to Photos OC. That way your UI will not freeze.
You might want to use the multithreaded ObservableColleciton you can find on code project. Search for ObservableCollectionMt...
I'm working on a desktop application. It has a dropdown menu. When a menu item is clicked on the dropdown a new tab is opened if it's not opened before. There is a single tab for a single dropdown menu item. What i want to do is to open a window, page or user control(i'm not sure which i should use) in seperate tabs considering the work they will do.
My partial XAML:
<dxd:DockLayoutManager DockItemClosing="DockLayoutManager_DockItemClosing_1">
<dxd:LayoutGroup>
<dxd:TabbedGroup Name="tabbedGroup">
</dxd:TabbedGroup>
</dxd:LayoutGroup>
</dxd:DockLayoutManager>
and partial CS:
private void addPanel(string caption)
{
var contains = false;
var layoutPanel = new LayoutPanel() { Caption = caption };
BaseLayoutItem[] baseLayoutItem = tabbedGroup.GetItems();
foreach (var layoutItem in baseLayoutItem)
{
if (layoutItem.Caption.Equals(layoutPanel.Caption))
{
contains = true;
}
}
if (!contains)
{
tabbedGroup.Add(layoutPanel);
}
}
As i mentioned i want to append a window, page or user control(i'm not sure which i should use) into every LayouPanel opened seperately.
Ok it's as easy as:
layoutPanel.Content = new UserControl1();
And i got one more trick for dynamically creating the desired tab:
layoutPanel.Content = Activator.CreateInstance(Type.GetType(Constants.s_tabs[caption]));
I hope it won't cause any performance problems.
I'm writing a Windows Phone Mango app. I have a hyperlink that contains email addresses. I want it to show a message box on tap:
Hyperlink href = new Hyperlink();
href.Click += (s, r) =>
{
MessageBox.Show("href clicked");
};
// add href to RichTextBox
When I click on the hyperlink in the emulator, nothing happens. The click += line is hit in a debugger, but the new EmailComposeTask() line isn't.
What am I doing wrong? Is Click not the event I want?
Update: I switched EmailComposeTask to MessageBox to verify that this issue isn't related to the email compose task not running on the emulator. I've reproduced this issue on my device.
The following code works:
GestureService.GetGestureListener(href); // adding this makes it work
href.Click += (s, r) =>
{
MessageBox.Show("href clicked");
new EmailComposeTask() { To = entireLink.Value }.Show();
};
href.Inlines.Add(new Run() { Text = entireLink.Value });
GetGestureListener creates a gesture listener if it doesn't already exist.
You should use HyperlinkButton Class, Hyperlink is a class used with rich text document rendering.
Following code is runs on device. text is RichTextBox object.
var linkText = new Run() { Text = "Link text" };
var link = new Hyperlink();
link.Inlines.Add(linkText);
link.Click += (o, e) =>
{
MessageBox.Show("Link clicked");
};
var paragraph = new Paragraph();
paragraph.Inlines.Add(link);
text.Blocks.Add(paragraph);
I am using the WPF webbrowser and basically when I load an external url, i want to filter any pages that are loaded to make sure the url doesnt contain a swear or porn type word.
This is easy to do on page load, as I check the URL against my List badwords; I have also set up a Load Completed method which gets me the url of clicked words, however this isnt working properly :-
void webBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
{
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)this.webBrowser1.Document;
foreach (IHTMLElement link in doc.links)
{
HTMLAnchorElement anchor = link as HTMLAnchorElement;
if (anchor != null)
{
HTMLAnchorEvents_Event handler = anchor as HTMLAnchorEvents_Event;
if (handler != null)
{
handler.onclick += new HTMLAnchorEvents_onclickEventHandler(delegate()
{
uxURLText.Text = anchor.href;
//if (HelperClass.isNotFile(anchor.href))
// {
if (basepage.nonSafeWords.WordsContainSwearWord(anchor.href))
{
System.Windows.MessageBox.Show(basepage.INTERNET_RESTRICTION_NOTICE);
}
else
{
System.Windows.MessageBox.Show("Word Ok");
}
return true;
});
}
}
}
}
I need to basically stop any bad content from loading in the window, either from link, button, or ajax if a bad link is clicked a popup needs to notify us. I also need to show the current url in the address bar
Please help many thanks
:)
Listen to the WebBrowser.Navigating Event (docs) and check the Uri in NavigatingCancelEventArgs. Then set e.Cancel = true if you to not want to allow the navigation.
But your valid Uri check is the more complex problem.
private void webBrowser1_Navigating(object sender, NavigatingCancelEventArgs e)
{
string currentURl= e.Uri.ToString();
_addrBox.Text = currentURl;
}
this was the solution in my case.
maybe itll help somebody