Modern UI how to go to another page from another link - c#

I am currently using Modern UI from CodePlex. It is great and easy to use but there are some classes and events that I am not familiar with. Example: I have two GroupLinks named "Patients" and "Configurations". There are several pages in each of the GroupLinks. I tried to navigate from one page to another using a button click event. It worked. But when I tried navigating from Page1 of GroupLink2 to Page1 of GroupLink1, it still worked, but the problem was the active GroupLink remained in GroupLink2 instead of GroupLink1 just like the screenshots show below:
Btw, I used the code behind to navigate from Allergies(IrritantPage) to PatientsPage:
private void FilterControl_OnToPatientClick(object sender, RoutedEventArgs e)
{
NavigationCommands.GoToPage.Execute("/MainContents/PatientGridPage.xaml", this);
}
So how do I solve this?
here are my MainWindow, Patient's Tab Page and Configuration's List Page
MODERN WINDOW (Main Window)
<mui:ModernWindow x:Class="DentalProto.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
Title="Dental" IsTitleVisible="True"
WindowStartupLocation="CenterScreen"
Width="1200"
Height="720"
ContentSource="/Pages/MainTabPage.xaml"
Closing="MainWindow_OnClosing"
>
<mui:ModernWindow.MenuLinkGroups>
<mui:LinkGroup DisplayName="User Name">
<mui:LinkGroup.Links>
<mui:Link DisplayName="Patients" Source="/Pages/MainTabPage.xaml" />
<mui:Link DisplayName="Configurations" Source="/Pages/ConfigurationsListNav.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
<mui:LinkGroup DisplayName="settings" GroupKey="settings">
<mui:LinkGroup.Links>
<mui:Link DisplayName="software" Source="/Pages/SettingsPage.xaml" />
</mui:LinkGroup.Links>
</mui:LinkGroup>
</mui:ModernWindow.MenuLinkGroups>
<mui:ModernWindow.TitleLinks>
<mui:Link DisplayName="settings" Source="/Pages/SettingsPage.xaml" />
<mui:Link DisplayName="help" Source="https://www.facebook.com/" />
</mui:ModernWindow.TitleLinks>
</mui:ModernWindow>
MAINTAB PAGE (Patient Page)
<UserControl x:Class="DentalProto.Pages.MainTabPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="1280">
<Grid >
<!-- TODO: set #SelectedSource -->
<mui:ModernTab Layout="Tab">
<mui:ModernTab.Links>
<!-- TODO: set #Source -->
<mui:Link DisplayName="Patient" Source="/MainContents/PatientGridPage.xaml" />
<mui:Link DisplayName="Treatment Record" Source="/MainContents/TreatmentFillInPage.xaml"/>
</mui:ModernTab.Links>
</mui:ModernTab>
</Grid>
</UserControl>
CONFIGURATIONLISTNAV (Configurations' Page)
<UserControl x:Class="DentalProto.Pages.ConfigurationsListNav"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Style="{StaticResource ContentRoot}">
<!-- TODO: set #SelectedSource -->
<mui:ModernTab Layout="List">
<mui:ModernTab.Links>
<!-- TODO: set #Source -->
<mui:Link DisplayName="Allergies" Source="/MainContents/IrritantGridPage.xaml"/>
<mui:Link DisplayName="Health Diseases" Source="/MainContents/HealthDiseaseGridPage.xaml"/>
<mui:Link DisplayName="Mouth Diseases" Source="/MainContents/MouthDiseaseGridPage.xaml"/>
<mui:Link DisplayName="Procedures" Source="/MainContents/ProcedureGridPage.xaml"/>
<mui:Link DisplayName="Dentists" Source="/MainContents/DentistGridPage.xaml"/>
</mui:ModernTab.Links>
</mui:ModernTab>
</Grid>
</UserControl>

You are mixing "page" navigation with "tab" navigation inside the ModernTab control.
If you call NavigationCommands.GoToPage.Execute inside a ModernTab control you are changing the current "tab", not the current "page".
To change the top level page you can use:
IInputElement target = NavigationHelper.FindFrame("_top", this);
NavigationCommands.GoToPage.Execute("/Pages/BasicPage1.xaml", target);
If the new page is another ModernTab and you want to select a different tab then the default one, then you have to put in place some extra code.
In example you could pass parameters to the new page.
Se this SO answer.

For anyone that may be struggling with this, set this in your MainWindow.cs constructor:
Application.Current.MainWindow = this;
Then in the part of your application where you want to navigate to a page, run this:
IInputElement target = NavigationHelper.FindFrame("_top", Application.Current.MainWindow);
NavigationCommands.GoToPage.Execute("/NameOfYourPage.xaml", target);

Related

WPF: How do I bind a window's ShowInTaskbar property to code-behind value?

I am attempting to bind my window's "ShowInTaskbar" property to a definition in the code-behind, but it is not recognized. I also cannot programmatically assign the value in code-behind. I can only manipulate it by directly editing the xaml, which is not ideal in my situation.
<Window x:Class="WPFTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WPFTest"
mc:Ignorable="d"
FontFamily="Segoe UI Light"
FontSize="14"
Title="WPF Test"
Name="Window"
Icon="/Resources/icon.ico"
Height="500"
Width="600"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
Loaded="Window_Loaded"
StateChanged="Window_StateChanged"
Closing="Window_Closing"
ShowInTaskbar="{Binding ShowInTaskbar}"
>
<Grid></Grid>
</Window>
The property I have in the code-behind:
private bool _showInTaskbar
public bool ShowInTaskbar
{
get
{
return _showInTaskbar;
}
set
{
_showInTaskbar = value;
OnPropertyChanged("ShowInTaskbar");
}
}
I have also tried:
Window.ShowInTaskbar = false;
Why is my binding not being recognized? Or, how can I simply define it in code-behind?
Ugh. It was because I was using the same name as the window naturally inherits. Once I changed my property to "ShowIconInTaskbar" I bound it and it functions properly.

How to Load a WPF window in the MainWindow as a TabControl item?

The structure of my MainWindow.xaml is as bellow
<Window>
<Grid>
<TabControl Name="MainTabCntrl">
<TabItem1>
<TabItem2>
<TabItem3>
.
.
.
<TabItemN>
</TabControl>
</Grid>
</Window>
The problem is that my MainWindow.xaml is currently ~4000 lines of code,which is not efficient(do you agree?)
the solution I'm trying to implement is to create N windows (representing my TabItems) separately and each time user click on Tab items I load the related windows in that TabItem as shown bellow
private void inventory_start()//this function is called in my MainWinodw.xaml.cs
{
inv = new Inventory(db, logViewer);//this is a window
TabItem tbItem = new TabItem();
Frame frame = new Frame();
frame.Content = inv;
tbItem.Name = "invTab";
tbItem.Content = frame;
tbItem.IsSelected = true;
MainTabCntrl.Items.Add(tbItem);
inv.swithInventoryTabs("inv_info");
}
I have an error now , "'Management_V0.Inventory' root element is not valid for navigation."
A window cannot be a child of another element. Period.
But you could just move the contents of the Inventory window to a UserControl (by for example simply copy and paste the XAML and the code from one file to another) and use this one as the Content of the Inventory window and the Frame:
<Window x:Class="WpfApplication1.Inventory"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="Inventory" Height="300" Width="300">
<local:UserControl1 />
</Window>
Frame frame = new Frame();
frame.Content = new UserControl1();
best way to use tabControl is with User control: Example below:
XAML
<TabControl >
<TabItem x:Name="tab1" Header="UserControl"></TabItem>
<TabItem x:Name="tab2" Header="noControl"></TabItem>
</TabControl>
and in code behind class:
tab1.Content = new UserControl1();
and than Add new user control of name UserControl1:
<UserControl x:Class="WpfApplication1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Viewbox>
<TextBlock Text="User Control"/>
</Viewbox>
</Grid>
</UserControl>

IO exception cannot locate resource 'basicpage1.xaml'

Hello I'm using Modern UI for WPF ,I have a page that contains a list with Items as links to other pages(User controls) my problem is when I press a link I have the error
System.IO.IO exception cannot locate resource 'basicpage1.xaml'
I have searched a lot but with no hope.
here is my XAML file for the list page:
<UserControl x:Class="ModernUINavigationApp.Pages.ListPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mui="http://firstfloorsoftware.com/ModernUI"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid Style="{StaticResource ContentRoot}">
<mui:ModernTab Layout="List" >
<mui:ModernTab.Links>
<!-- TODO: set #Source -->
<mui:Link DisplayName="Item 1" Source="/basicpage1.xaml"/>
<mui:Link DisplayName="Item 2" />
</mui:ModernTab.Links>
</mui:ModernTab>
</Grid>
</UserControl>
The Exception
Solution Explorer
basicpage1.xaml is located in your Pages directory so you should add /Pages to the source:
<mui:Link DisplayName="Item 1" Source="/Pages/basicpage1.xaml"/>
I just encountered the same kind of problem when setting a Frame Source to a page.
When checking file properties in solution explorer I noticed that VS has put the page file in a subdirectory of the application file (in my case VS named the subdirectory "My Project") so I rewrote
<Frame Source="/Page1.xaml"/>
to
<Frame Source="/My Project/Page1.xaml">
and it solved the problem.
Just check and compare the full path property of application.xaml versus your basicpage1.xaml"

How to define UserControl with custom content?

I want to define my custom decorator that has user content in it. But it always fail when I try to set some control's name. I always get this exception when trying to do it:
Cannot set Name attribute value 'butt' on element 'Button'. 'Button'
is under the scope of element 'UserControl1', which already had a name
registered when it was defined in another scope.
I don't understand why that happens. Here's teh codez:
<UserControl x:Class="WpfApplication5.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
x:Name="control">
<ContentPresenter Content="{Binding ElementName=control, Path=DataContext}" />
</UserControl>
<Window x:Class="WpfApplication5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication5"
Title="MainWindow" Height="350" Width="525">
<local:UserControl1>
<local:UserControl1.DataContext>
<Button x:Name="butt" />
</local:UserControl1.DataContext>
</local:UserControl1>
</Window>
How to do that properly?
You cannot name elements inside UserControls, someone considered this to be a bug but i do not know if this is the case, either way, this will not work. You could declare the Button as a resource of your Window and then insert it via StaticResource, then however the name will not be registered as a field in the window class.
Either way, do you really need the name?
Edit: Also see this question.

Bringing a user control to the front in Expression Blend, C#, WPF

I have a window with a Grid on.
On this I have some buttons, one of which when clicked will create a new 'PostIt' which is a user control I have created.
What I want to do is click on a 'PostIt' and have that control on top of all the others.
I have tried...
Grid.SetZIndex(sender, value);
Which seems to be the correct code, no errors, just not movement of the control :(
The problem may lie in the fact that the code for the click is in the user control and not the mainwindow cs file. Does this matter?
The 'PostIt' is simply a border with a text box in it.
Are you calling Grid.SetZIndex(sender, value) in a handler of the PostIt mouse click, or a handler for a control inside the PostIt? What is the value that you are setting?
Here is an example that works:
<UserControl x:Class="WpfApplication1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" MouseUp="UserControl_MouseUp">
<Grid>
</Grid>
</UserControl>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
{
Panel.SetZIndex(this, Panel.GetZIndex(this) + 2);
}
}
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Grid>
<local:UserControl1 Background="Green" Margin="40,40,100,100" Panel.ZIndex="0" />
<local:UserControl1 Background="Red" Margin="140,140,10,10" Panel.ZIndex="1" />
</Grid>
</Window>
Jogy
This may not be the best solution, but it's the one that worked for me; I was re-ordering two grids:
GridOnBottom.SetValue(Grid.ZIndexProperty, (int)GridOnTop.GetValue(Grid.ZIndexProperty) + 1);
...with GridOnBottom and GridOnTop renamed to the instances of the objects you're re-ordering. Granted, it's not the best solution, but it works.

Categories