I have a Form called EmployeeForm inside this form i'm including some UserControl and when I edit EmployeeForm every UserControl inside the form are lost.
This picture show a diff between TFS(left) and Local(right) file, after modifying the name of a combobox
Example of this.ucEmployeeKeyOne :
public partial class Employee_EmployeeKeyOneRelationUC
: Employee_EmployeeKeyOneRelation_GenericUC
{ [other Code Here] }
public class Employee_EmployeeKeyOneRelation_GenericUC
: RelationUC<MyObject>
{ }
and the definition of RelationUC :
public partial class RelationUC<T>
: DataUserControlBase
{ [other Code Here] }
public partial class DataUserControlBase
: UserControlBase
{ [other Code Here] }
public partial class UserControlBase
: System.Windows.Forms.UserControl, MyInterfaceHere
{ [other Code Here] }
All UserControl i'm losing are inherited from RelationUC<T>. Does the generic type of RelationUC may cause the problem?
For the Vs designer to load the controls, the control should be able to initialize including all public properties and you must have a empty constructor. If you don't have an empty constructor or have properties that are returning from the inherited nullable class, it is most likely the the designer will crash.
To Debug this,
1) open you project in VS but do not open the file that contains the controls yet;
2) open another VS and attach the process of VS that your project is opened;
3) set the break on exceptions (short cut 'CTRL + D, CTRL +E' ) to all (once you become familiar with what exception the designer is throwing, you can set that exception only.);
4) Go to the VS with you project and open the file that contain your user control. when the exception is thrown, the second VS will catch it and tell you exactly why and where.
Related
I am creating a custom C# Windows Forms control library (a DLL) in Visual Studio 2019 (Professional). My control has a property that takes the following form (this property is aimed to be accessed by applications which use the DLL):
public double Hello
{
get { throw new ApplicationException("Hi!"); }
}
(In my efforts to find out why this is happening, I've simplified the property to just throw an exception and do nothing else.)
For some reason, if I run my User Control (in Debug mode), the exception is raised - even though nowhere else in this code calls that property! (The IDE confirms this - saying "0 references" above it). Why does the property "get" accessor seem to be called for no reason? The stack trace shows that the "get" was called by "[External code]"...
This should be pretty easy to reproduce if you have Visual Studio 2019: create a new "Windows Forms Control Library (.NET Framework)" project under C#, then right click on "UserControl1.cs" in the Solution Explorer and click "View Code", then just add in the above code to the class.
I have reproduced your problem. Based on my test, I find that winformscontrollibary will
load all the properties you set in the code, because it needs to load them into the
property bar of form.
Like the following, if you write the following code.
public partial class UserControl1: UserControl
{
public UserControl1()
{
InitializeComponent();
}
public double Hello
{
get { return 1.02; }
}
public int Number
{
get { return 1; }
}
}
You will see the correct property(Hello and Number) in the right of form.
Therefore, if you write the code throw new ApplicationException("Hi!"); in the get method , it will throw the exception.
I have created a boolean algebraic simplifier. It simplifies expressions and I am content with it. However, I am trying to add a feature that allows users to check if two expressions are equivalent. For this I have created a new form that allows the user to input two expression by clicking buttons. To do this, I thought it best to simplify both expressions and then compare the two for equivalency. As I have got lots of subroutines and code that works for simplification in another form, I thought making the form a child form of the form with the code in would allow me to call the subroutines instead of copying them onto the form. I have made these protected in the parent form. I have inherited like so:
public partial class Expression_Equivalency_Form : Expression_Simplifier
However, when I click onto the form designer, this error appears and I cannot view the graphical interface of the form:
"Could not find file File Path"
The file is in the debug folder which is within the bin folder within the folder containing the program and is recongised in the parent class. The file is read from and appeneded by the parent form without issue. I have tried to research this but have been unable to find a solution. Does anyone know one?
I have read to the file and appended to it. I have also used the following code to remove any blank lines from my text file:
File.WriteAllLines("PreviousExpressionInputs.txt",
File.ReadAllLines("PreviousExpressionInputs.txt").Where(l => !string.IsNullOrWhiteSpace(l)));
Code that writes to the file:
using (BinaryWriter Writer = new BinaryWriter(File.Open("PreviousExpressionInputs.txt",
FileMode.Append)))
{
Writer.Write(expressionandanswertowritetotextfile);
}
Code that reads from the file:
foreach (string line in File.ReadLines("PreviousExpressionInputs.txt"))
{
try
{
LinesInFile.Add(line);
}
catch (Exception)
{
}
}
Consider following facts:
When you open a form in design mode, the constructor of its base class will run.
When you look for a relative file name, the path will be resolved relative to the current working directory of the application.
When the form is in design mode, the current application is Visual Studio and its working directory is where the devenv.exe is located.
It describes why you cannot find your text files. Because you have some code in the constructor of your base form(or fir example load event handler of the base form) which looks for the file and since the filename is relative, its looking for the file in the Visual Studio working directory and could not find file.
How to prevent the problem? Check DesignMode property to prevent running the code:
public partial class MyBaseForm : Form
{
public MyBaseForm()
{
InitializeComponent();
}
private void MyBaseForm_Load(object sender, EventArgs e)
{
MessageBox.Show("This will show both in run-time and design time.");
if (!DesignMode)
MessageBox.Show("This will show just in run-time");
}
}
Create the derived form and open it in designer to see what happens:
public partial class Form1 : MyBaseForm
{
public Form1()
{
InitializeComponent();
}
}
To learn more about how designer works take a look at this post.
I am trying to inherit from a base page instead of Normal Page control of XAML but Visual Studio is giving me compile time errors that OnNavigatedTo method not found to be overridden.
I am doing this because I have multiple pages with a lot of similar code and I want to write that code just once, so I want to write that code in parent class and then inherit all pages from that parent class, I followed guidelines as stated on multiple resources on internet and below is my code.
Parent Class:
public class VideoParentPage : Page
{
}
Child Class (AllVideoPage.xaml.cs):
public sealed partial class AllVideosPage : VideoParentPage
{
public AllVideosPage() : base()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
SetBanner();
}
}
XAML in file AllVideosPage.xaml:
<local:VideoParentPage
xmlns:local="using:Fluent_Video_Player.Views.Shared"
...some unrelated XAML code...
</local:VideoParentPage>
Note: I have used all necessary using statement in C# classes.
You should try cleaning the solution Build > Clean Solution, closing VS, removing the remaining bin and obj folders and then compiling the app again.
I'm trying to break up a very big VSTO IRibbonExtensibility class into multiple smaller classes to make things more manageable.
I tried creating a partial class with all my Visibility callbacks in it.
The code compiles fine but doesn't work in MS Word.
Error: The call to GetCustomUI() for RibbonID 'Microsoft.Word.Document' failed.
Any idea why this isn't working??
[ComVisible(true)]
public partial class Ribbon : O.IRibbonExtensibility
{
..
}
public partial class Ribbon
{
..
}
Sorry, my bad..
I had moved the Ribbon.xml file into a new folder and that caused the issue
I have actually tried to fix this.
Basically i cannot start my project anymore with the error
Error 1 Missing partial modifier on declaration of type 'SystemTools.Controls.User.SideBar'; another partial declaration of this type exists
[PathRemovedManually]obj\Debug\Controls\User\SideBar.g.cs 41 18 SystemTools
I have attempted to change the code in this file to
public partial class SideBar : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {
Howevever everytime i rebuild it reverts back to
public class SideBar : System.Windows.Controls.UserControl, System.Windows.Markup.IComponentConnector {
I have also deleted my entire debug folder and still having issues.
Can someone give me any ideas ?
SideBar.g.cs is autogenerated dont edit that file manually. Try to check your XAML declaration for SideBar control. And yes, as response to your comment those craps have meaning and commonly are required.