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"
Related
Yesterday I create a project in my disk D partition and I found the images I put into project can't be displayed well. XAML code below is very simple:
<Window x:Class="WpfImageTest.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:WpfImageTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Image Width="300" Height="300" Source="/Resources/Images/Chen.png"/>
</Grid>
</Window>
You can see I write a relative path for Image control's Source property and when I run the application it shows nothing on the interface.But magically I copy all the files into the root of my C partition or D partition of my physical disk and rebuild the project, the application runs properly. This proplem troubles me almost all day , can anyone explain why this thing happens?
The original location of my project is D:\Programming\C#\Practice\WpfImageTest and I have already set all images build property to Copy all the time and Content.
Select your image file in your Solution Browser and set its Build Action to Resource as on image below.
I am creating a universal app in Visual Studio 2015. My universal app has a reference to a universal library called UIComponents.
In UIComponents I created a user control:
namespace MyProj.UIComponents {
public sealed partial class MyControl : UserControl
{
public MyControl()
{
this.InitializeComponent();
}
}
}
With the following xaml:
<UserControl
x:Class="MyProj.UIComponents.MyControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyProj.UIComponents"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Grid>
<Rectangle Fill="White" HorizontalAlignment="Left" Height="280" Stroke="Black" VerticalAlignment="Top" Width="380" Margin="10,10,0,0"/>
<TextBox x:Name="textBox" Margin="20,20,20,20" TextWrapping="Wrap" Text="TextBox"/>
</Grid>
</UserControl>
Inside my app project, which references UIComponents, I do this:
<Page
x:Class="MyProj.App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyProj.App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:MyProj.UIComponents"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ui:MyControl></ui:MyControl>
</Grid>
</Page>
But when I try to get the designer display the page I get:
The error list shows this:
The name "MyControl" does not exist in the namespace
"using:MyProj.UIComponents".
Funny thing is that the whole solution builds just fine, but the designer is not collaborating.
Attempt using clr-namespace
There are similar questions about this in WPF, so not strictly universal apps, and they are marked as solved on answers where the solution was to use:
xmlns:ui="clr-namespace:MyProj.UIComponents"
Bu that does not work:
Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace
'MyProj.UIComponents' that could not be found.
The error list shows this:
The name "MyControl" does not exist in the namespace "using:MyProj.UIComponents".
In my experience, this could probably be caused by
The UIComponents Library didn't got built.
After building the Library project, VS will add the following codes into YourProject.proj file, which will be detected by VS designer:
<ItemGroup>//The following lines will be added.
<Page Include="MyControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
So, please try building your library project and rereference it in your main project.After reloading, designer should load the contents correctly.
Notes: The architecture(x64,x86) when building your library should be identical to current architecture. (e.g. when you build your library with x86. Designer can't load correctly, when your current architure is x64).
The namespace is wrong, which seems not the main cause here.
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);
I can create UserControl and add TextBox very easily in Surface environment. Here is a sample code:
<UserControl x:Class="ScatterViewSizingSample.FixedSizeChild"
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:local="clr-namespace:ScatterViewSizingSample"
mc:Ignorable="d" local:PopupWindow.InitialSizeRequest="300,250"
d:DesignHeight="300" d:DesignWidth="250">
<Grid Background="MediumSeaGreen">
<TextBox HorizontalAlignment="Left" Name="textBox1" VerticalAlignment="Top"/>
</Grid>
</UserControl>
I tried to add SurfaceUserControl and SurfaceTextBox, but I cannot find to add SurfaceUserControl from the menu. I changed UserControl to s:SurfaceUserControl and Texbox to s:SurfaceTextbox as follows:
<s:SurfaceUserControl x:Class="ScatterViewSizingSample.FixedSizeChild"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.microsoft.com/surface/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ScatterViewSizingSample"
mc:Ignorable="d" local:PopupWindow.InitialSizeRequest="300,250"
d:DesignHeight="300" d:DesignWidth="250">
<Grid Background="MediumSeaGreen">
<s:SurfaceTextBox HorizontalAlignment="Left" Name="textBox1"/>
</Grid>
</s:SurfaceUserControl>
But the system shows error that 'the type s:SurfaceWindows does not found'. I added Microsoft.Surface.Presentation and Microsoft.Surface.Presentation.Generic assembly reference. But it still shows error.
How can I fix it? Why the system does not show SurfaceUserControl as UserControl?
An application using Surface controls needs to use SurfaceWindow as it's root visual in order to do all of the custom touch handling. I suspect that since you're trying to convert this you are probably still using a standard Window which is giving you this error.
If you're developing for 2.0, SurfaceUserControl no longer exists, as per MSDN:
The SurfaceUserControl class has been removed in Surface 2.0. The SurfaceUserControl class was needed in Surface 1.0 SP1 to add touch support to user controls. However, touch support has been added to the UserControl class in .NET Framework 4. To convert your code, remove "s:Surface" from the front of "s:SurfaceUserControl", or use the Surface Migration PowerToy.
Source
Hi I am creating my first WPF application that uses Ribbons. The problem I am having is I cannot change the theme of the ribbons. I want to use the Office 2007 Black theme. I have looked everywhere and everywhere I find roughly the same example, I have tried writing it from scratch, copy pasting and everything but it keeps throwing an exception when I try t run the application.
Exception
Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '11' and line position '18'.
Inner Exception
{"Cannot locate resource 'themes/office2007black.xaml'."}
Xaml Code
<r:RibbonWindow x:Class="DtcInvoicer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
Title="Dtc Invoicer"
Width="1000" Height="650" WindowStartupLocation="CenterScreen">
<r:RibbonWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/RibbonControlsLibrary;component/Themes/Office2007Black.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</r:RibbonWindow.Resources>
<Grid x:Name="LayoutRoot">
<r:Ribbon x:Name="TopMenuRibbon" Title="First Ribbon">
<r:RibbonTab Header="Home" />
<r:RibbonTab Header="Company" />
<r:RibbonTab Header="Employees" />
<r:RibbonTab Header="Receivables" />
<r:RibbonTab Header="Payables" />
<r:RibbonTab Header="Inventory" />
<r:RibbonTab Header="Settings" />
</r:Ribbon>
</Grid>
</r:RibbonWindow>
Anyone have idea why that might be happening? The RibbonControlsLibrary is in my references, everything works fine and the ribbons come up in the blue theme until I try to switch to black or silver, then I get the exception.
Resources that are specific to a theme are kept in a resource dictionary with a specific file name. These files must be in a folder named Themes that is a subfolder of the folder that contains the control.
See this MSDN article for more details.