I am making a Property Sheet shell extension using SharpShell. Initially I tried using WinForms for the Property page, but the limitations of controls like PropertyGrid, ListView etc. made me choose WPF. So I created a WPF User Control Library project and added SharpShell to my project from Nuget.
I made a new Page, I guess, I am new to VS & WPF, but it shows "Build Action" as "Page". Now my code-behind looks like this:
using SharpShell.SharpPropertySheet;
using SharpShell.Attributes;
using System.Runtime.InteropServices;
namespace FLPShellExtension
{
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".flp")]
public partial class FLPPropertyPage : SharpPropertyPage
{
public FLPPropertyPage()
{
InitializeComponent();
PageTitle = "Project Info";
}
}
}
XAML looks like this:
<UserControl x:Class="FLPShellExtension.FLPPropertyPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:wc="clr-namespace:FLPShellExtension;assembly=SharpShell"
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="450" d:DesignWidth="800">
<Grid></Grid>
</UserControl>
Here, VS complains of two things:
CS0103: The name 'PageTitle' does not exist in the current context
XAML1103: Namespace 'wc' is unnecessary
The PageTitle = "Project Info" worked in WinForms. It is a public string defined in SharpPropertyPage. I found about this wc namespace from a similar question asked elsewhere.
Related
I try to understand C# prism framework, and make a little project. I meet some problem with misunderstanding Prism concept. I will explain what i want to do, what i try, my code:
I want to make a simple application like a test with 5 random question. You select difficult of test after you press start. On the same window your page is change with first question. Select right answer , next and you go on the second page with second question. From the second question you have 2 buttons(prev and next) , next next next, finish and you have a message like "you got x/5 points".
I have a similar aplication but the framework use is Caliburn.
First Application
I want to put all questions in xaml file now.
What i try:
I follow documentation, youtube tutorials for 2 days.
I create 2 folders: View and ViewModel. Create MainPage.xaml like a window in View and in ViewModel i create MainPageViewModel, in file MainPage.cs i create one instance like:
MainPageViewModel main = new MainPageViewModel();
After this i create a button i test the button and work.
Now I want to create a Page to connect with MainPageViewModel window. In the page i want to create another button and i want to check if is work. But this is the step how can't create.
After follow few tutorials, i can't make this. Not work to connect on the xaml file MainPageViewModel.
MainPage:
<Window x:Class="Aplicatie2._0.View.MainPage"
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:prism="http://prismlibrary.com/"
xmlns:local="clr-namespace:Aplicatie2._0.View"
prism:ViewModelLocator.AutoWireViewModel="True"
mc:Ignorable="d"
Title="{Binding Title}" Height="450" Width="800">
<Window.DataContext>
</Window.DataContext>
<Grid>
</Grid>
</Window>
Error MC3063: Property 'DataContext' does not have a value. Line 14 Position 30.
MainPageViewModel:
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Commands;
namespace Aplicatie2._0.ViewModel
{
class MainPageViewModel : BindableBase
{
private string _Title = "Test";
public string Title
{
get
{
return _Title;
}
set
{
SetProperty(ref _Title, value);
}
}
}
}
App.xaml:
<prism:PrismApplication x:Class="Aplicatie2._0.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
xmlns:local="clr-namespace:Aplicatie2._0">
<Application.Resources>
</Application.Resources>
</prism:PrismApplication>
App.xaml.cs:
using Prism.Modularity;
using Prism.Ioc;
using System.Windows;
using System.ComponentModel;
using Prism.Unity;
using Aplicatie2._0.View;
namespace Aplicatie2._0
{
public partial class App : PrismApplication
{
protected override Window CreateShell()
{
return Container.Resolve<MainPage>();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<MainPage>("MainPage");
}
}
}
1)How can i create multiple page and how can connect with main window?(If i call page1 i want to be clear, to create button and Radiobutton on the page)
2)How can i connect ViewModel file with View file on xaml, without create instance?
3)How can i create one question in xaml like:
Question: This is first question
[] Answer1
[] Answer2
[] Answer3
If you can to give me an example it's perfect, but make it simple.
I am aware that there are other questions posted that appear to be the same issue but none of them fix my issue.
I'm new to WPF I'm trying to convert a program from WinForms to WPF. I have a main window, "Kproj.Forms.frmLogin", that inherits a base class, "Kproj.Forms.frmSwitch", that inherits the System.Windows.Window class. WhenI got the above issue, my initial XAML code was:
<Control:frmSwitch x:Class="Kproj.Forms.frmLogin"
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:Control="clr-namespace:Kproj.Forms"
mc:Ignorable="d"
Title="LOG IN" Height="309" Width="678">
<Grid Height="271" Width="662">
... Content
</Grid>
</Control:frmSwitch>
with these in the code-behinds:
namespace Kproj.Forms
{
public partial class frmLogin : frmSwitch
{
}
}
namespace Kproj.Forms
{
public partial class frmSwitch : Window
{
}
}
Upon further research, I found out that I needed to make frmSwitch into a base class with no XAML. Thus, I created frmSwitch2 in just general Class form that looks like this:
namespace Kproj.Forms
{
public class frmSwitch2 : Window
{
}
}
I then adjusted the main window XAML accordingly:
<Control:frmSwitch2 x:Class="Kproj.Forms.frmLogin"
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:Control="clr-namespace:Kproj.Forms"
mc:Ignorable="d"
Title="LOG IN" Height="309" Width="678">
<Grid Height="271" Width="662">
... Content
</Grid>
</Control:frmSwitch2>
and the main window code-behind to:
namespace Kproj.Forms
{
public partial class frmLogin : frmSwitch
{
}
}
Now, I lost the original error message, but I gained a message that states
"The name 'frmSwitch2' does not exist in the namespace 'clr-namespace:FITS.Forms'."
even though it suggests "frmSwitch2" when I type "Control:" in the main window XAML, so it knows it does exist in the namespace. Any suggestions?
Disclaimer: I tried researching it as best as possible but all the posts I found on StackOverflow were this issue but all were fixed by converting from XAML\cs partial classes to solo code-behind full XAML-less class.
After looking into what the inheritance actually wanted, I learned that the only purpose of the inheritance was for variables so I was able to make it work but just converting them to static global variables and accessing them directly. I ended up not needing the inheritance after all.
If anyone else, that ends up knowing more MVVM, does come across a fix for this issue, it would be nice to know it. Even though I no longer need it, it would be good learning.
I have a windows phone project where I've added a usercontrol:
namespace MyApp.WindowsPhone.UserControls
{
public partial class SlidingUpOverlay : UserControl
{
public SlidingUpOverlay()
{
InitializeComponent();
}
}
}
Then I'm referencing it in a Page like this:
<phone:PhoneApplicationPage
x:Class="MyApp.WindowsPhone.UI.TopUpPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:userControls="clr-namespace:MyApp.WindowsPhone.UserControls">
<userControls:SlidingUpOverlay x:Name="SlidingUpOverlay" Visibility="Collapsed" />
But building it gives me following error:
The type or namespace name 'UserControls' does not exist in the namespace 'MyApp.WindowsPhone.MyApp.WindowsPhone' (are you missing an assembly reference?) MyApp-WP C:\Users\MyApp\developers\apps\MyApp-WP\MyApp-WP\obj\Debug\UI\TopUpPage.g.i.cs
I've cleaned bin and obj-folders, restarted computer, restarted VS2015, tried everything suggested but nothing works. I've also read through many pages here on stackoverflow but haven't found anything the suggests anything else than I've already tried. What am I missing?
xmlns:userControls="clr-namespace:MyApp.WindowsPhone.UserControls"
You could try changing this line to:
xmlns:userControls="using:MyApp.WindowsPhone.UserControls"
Change the namespace of user control:
namespace MyApp
{
public partial class SlidingUpOverlay : UserControl
{
public SlidingUpOverlay()
{
InitializeComponent();
}
}
}
Then add the following reference in your Xaml Page:
xmlns:userControls="clr-namespace:MyApp">
P.S. Also change the Xaml schema of your User control
x:Class="MyApp.SlidingUpOverlay"
I am starting working with MVVMCross.
I had created the View and view model.
The View.xaml look like that:
<views:MvxWindowsPage
x:Class="xxx.Client.UWP.Views.View1"
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:views="using:Cirrious.MvvmCross.WindowsUWP.Views"
mc:Ignorable="d">
But I get this error:
The name "MvxWindowsPage" does not exist in the namespace "using:Cirrious.MvvmCross.WindowsUWP.Views"
But in my View.xaml.cs i had inherited from it without error:
public sealed partial class View1 : Cirrious.MvvmCross.WindowsUWP.Views.MvxWindowsPage
Do you know what the problem is?
Thanks.
I tested it with MvvmCross 4.0.0-beta3, and it works without any problem.
If you are using the correct version, see if you can repro the issue using the following steps. Just want to make sure we are doing the same thing.
In Visual Studio 2015 RTM-> new-> project-> c#-> windows-> universal-> Blank App(Universal Windows) name it "Test.Client.UWP".
Right click on the project node in VS solution explorer -> Manage NuGet Packages -> Check "include prerelease" and search mvvmcross -> Select the Latest prerelease 4.0.0-beta3 and install. (make sure there is no error in output window)
Add Views folder in the project root -> Add a blank page named View1 -> do the following changes:
Change to View1.xaml.cs
namespace Test.Client.UWP.Views
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class View1 : Cirrious.MvvmCross.WindowsUWP.Views.MvxWindowsPage
{
public View1()
{
this.InitializeComponent();
}
}
}
Change to View1.xaml
<views:MvxWindowsPage
xmlns:views="using:Cirrious.MvvmCross.WindowsUWP.Views"
x:Class="Test.Client.UWP.Views.View1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Test.Client.UWP.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
</Grid>
</views:MvxWindowsPage>
When I include an assembly containing a ResourceDictionary using the following pack syntax:
"pack://application:,,,/WpfCore;component/ResourceDictionaries/ThemedControls.xaml"
It works as expected, but as soon as I add a code behind file to the XAML of the ResourceDictionary, the following error is thrown:
“An error occurred while finding the resource dictionary”
The code behind is added to the XAML in the usual way:
< ResourceDictionary x:Class="com.mycompany.WpfCore.ResourceDictionaries.ThemedControls"
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">
</ResourceDictionary>
and looks like this:
namespace com.mycompany.WpfCore.ResourceDictionaries
{
public partial class ThemedControls : ResourceDictionary
{
public ThemedControls ()
{
InitializeComponent();
}
}
}
Intuition tells me this is a namespace problem, but all the variations I've tried fail. What am I doing wrong or is this a limitation of WPF ResourceDictionaries?
Edit:
Seems the question detail was called out and found to be wanting.
The initial example had the namespace simplified. The default namespace for the WpfCore project is com.mycompany.WpfCore which I have now added into the code examples above.
The ThemedControls.xaml and ThemedControls.xaml.cs files are located in a subfolder called ResourceDictionaries within the WpfCore project folder.
The resulting assembly is used as a referenced assembly in another solution and this is where the Pack URI is being used.
Edit 2:
After playing around with the build action for the xaml files (changing from page to resource and back again) things started working. Marking Sheridan's answer as correct.
I don't think that you have declared your ResourceDictionary quite correctly... the application name really should be in the namespace. This should work... at least it works for me:
<ResourceDictionary
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"
x:Class="WpfCore.ResourceDictionaries.ThemedControls">
</ResourceDictionary>
Code behind:
namespace WpfCore.ResourceDictionaries
{
public partial class ThemedControls : ResourceDictionary
{
public ThemedControls()
{
InitializeComponent();
}
}
}