I need to know how to set the very top left icon / image on a WPF page. I know how to do it in a WPF Window the page looks to be different.
Thanks,
Darren
I don't think there's any support for changing the host window's icon based on its current page in a navigation-style application.
One workaround might be to introduce a property of type Image into your pages (perhaps derive all your pages from a base page, or introduce an IHasIcon interface and implement that), then bind the host window's icon to that. Something along the lines of:
<Window ...
Icon="{Binding Content.Icon,ElementName=frame1>
<Frame x:Name="frame1" ... />
</Window>
I haven't tried this but I've done similar things with binding a TextBlock to the "title" of the current page in a navigation application.
It is possible to modify the icon of the host window by adding the following (VB) code to the Loaded event of the page (I didn't test placing the code in the constructor).
Dim hostWindow As NavigationWindow =
DirectCast(
DirectCast(Me.VisualParent,
System.Windows.Controls.ContentPresenter).
TemplatedParent,
System.Windows.Navigation.NavigationWindow)
Dim iconUri As New Uri("MyIcon.ico", UriKind.RelativeOrAbsolute)
hostWindow.Icon = BitmapFrame.Create(iconUri)
Are you referring to a WPF application deployed as an XBAP, if so the same rules apply as a normal website and you would just place a favicon.ico in the root of your IIS website.
http://en.wikipedia.org/wiki/Favicon
Related
I have this application where there is a frame and I navigated the frame to a different Page where there are certain button which must be able to navigate the frame to another page but i don't know how to change the navigate property of the frame from another class somewhere. Can anyone help me out with that and also how do i change the text property of the page identifier from the another class.
Could you please try this? On button click event handler.
framename.Navigate(new Page1());
where Page1 is a xaml file to which you need to navigate to.
EDIT :
Your requirement could be easily implemented using MVVM model. The basic concept behind MVVM is that you can bind your data to properties in the view model class. So that you could easily control the properties of child classes from parent class and vice versa using instances of view model classes.
Could you try this for the time being?
((MainWindow)System.Windows.Application.Current.MainWindow).Framename.Navigate(new Page());
Also try this, to make the component as public.
For access controls in other WPF windows, you have to declare that control as a public, the default declaration of controls in WPF is public, and you can specify it with this code:
<TextBox x:Name="textBox1" x:FieldModifier="public" />
And after than you can search in all active windows in application to find than windows have that control like this:
foreach (Window window in Application.Current.Windows)
{
if (window.GetType() == typeof(Window1))
{
(window as Window1).textBox1.Text = "I change it from another windows";
}
}
I'm building a Silverlight out-of-browser app that will eventually run on a Windows 7 touchscreen tablet, independent of any browser - it will run just like any other app.
My code, at the moment, is all within one XAML and corresponding .cs file but this is messy and I'd like to split it out and call each page as and when required i.e. Main.xaml, AboutUs.xaml, Contact.xaml etc.
Is this possible in an OOB app? I tried to use the frame and pages controls, but when I set the source to one of my new XAMLs via a button click i.e. "/AboutUs.xaml", it tells me that it's an invalid URI.
Thanks,
Greg.
Try and create a root canvas (e.g: myCanvas) in your MainPage.xaml to act as a container which displays all your pages.
On navigation clicks, write this.
myCanvas.Children.Clear();
myCanvas.Children.Add(new myPage());
A good practice is to set a public property on every page
public MainPage parentPage;
in this case, to which you can assign the parent page that hold that root canvas (myCanvas in case). On further pages, you just navigate using
parentPage.myCanvas.Clear();
anotherPage tempPage = new anotherPage();
tempPage.parentPage = parentPage;
parentPage.myCanvas.Add(tempPage);
I want to make a program by WPF which includes several pages.
I have a Window and several Pages now.
In order to navigate, I use
this.Content = new Page1();
in the main window (from Window to Page), and
((Window)this.Parent).Content = new Page1();
between pages (from Page to Page), because Page can only be sub-element of Window or Frame.
However, the second line of code above looks quite ugly.
Is there a better way to achieve the same goal?
I have coded from several Windows Phone applications before, and I think it might be better to navigate between Pages rather than hide/show elements (such as Grids).
If your navigation code is on your Page class, either :
move it to the window class
create an event in the Page class, and react to it on the Window class.
Is there any reason why you can't just put a Frame in your Window ?
You could use NavigationService.
http://msdn.microsoft.com/en-us/library/ms750478.aspx
http://www.paulstovell.com/wpf-navigation
Maybe this could help:
http://azerdark.wordpress.com/2010/04/23/multi-page-application-in-wpf/
A "simple" situation:
Assembly1 contains:
A couple of WPF Pages (.xaml)
Calling Assembly contains:
A WinForm with an ElementHost
The ElementHost contains a WPF UserControl that has a single Frame (=MainFrame)
The WinForm uses the NavigationService from the MainFrame to navigate to an absolute Uri in a like this:
NavigationService.Navigate(new Uri("pack://application:,,,/Assembly1;component/Page1.xaml", UriKind.Absolute);
Navigated page is displayed, all fine until now. Now when I look at the NavigationService.CurrentSource (which is the Uri of the currenlty loaded page) it looks like this:
All kinds of Exceptions...And what is also weird is that the property IsRelative is True and the OriginalString property states : "/Assembly1;component/Page1.xaml". The whole "pack-part" is lost. So when using the Uri again (what i would like) results in errors because this Uri doesn't give me a correct path anymore.
Am I missing some essential part of the NavigationModel in WPF? Any help would be appreciated!
What I choose as a solution is to pick up the
NavigationService.CurrentSource
and paste the "pack-part"in front of it again. Then use it again for navigation.
I am using the Frame navigation control. Programmatically, I specify the page to fill the frame (like "Views\Home.xaml"). The browser is currently using string specified in the Frame control as the name of the page; in other words, the browser displays "Views\Home.xaml" as the name of the page.
I tried setting the "Name" property on the frame control, but that does not effect the name displayed by the browser.
If you are using the navigation control, you do have access to (e.g. navigation:Page) and that contains a Title property.
Now, you say that you programmatically specify the page to fill the frame, however you do not specify if you are simply browsing there programmatically.
If you set up your UriMapper to contain something like the following:
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml" />
Then you can navigate to any page from the code-behind by simply using the Uri Format. For example:
ContentFrame.Navigate(new Uri("/About", UriKind.Relative));
will browse to /Views/About.xaml but will provide a page name of:
http://localhost:2568/FileDownloadNavigationTestPage.aspx#/About
Try setting the title property of the page.
The Silverlight navigation framework consists of two main visual parts.
The System.Windows.Controls.Navigation.Frame which will host each page. Now the frame can host a UserControl but what it should be given is a page of type System.Windows.Controls.Navigation.Page which has a property on it called Title. The frame then uses the Title property as the title for the browser to use.