Using a custom font throughout the project - c#

I've got a Prism project with a dozen modules in it.
I want to use a custom font (a .TTF file, to be specific) in all the modules.
When I put the .ttf file in the module folder - it works, but what if I add a dozen more modules?
So, I want to have the file in one place.
At tried to put the font in %projectname%.Web/Clientbin, because it worked with images and everything, but it doesn't work. =(
Can you give me some advise?
Example of the code:
<HyperlinkButton
FontFamily="/fonts/AZGR45_C.TTF#AZGaramondC">
www.samplelink.com
</HyperlinkButton>

Using PRISM generally means you have a few projects.
Application.Shell: Your startup application containing the app.xaml
Application.Module: Your different modules
Application.Infrastructure. Containing general classes for your
application. Every module and the shell has a reference to this
project. In example you might have Interfaces for certain services
like CustomerServices. This also allows you to have certain styling
or datatemplate or even fonts in this Infrastructure project
Hope this helps

Related

WPF Project with Custom XAML Controls

I am new to WPF coding. I have a project that has custom controls coded as xaml's with C# code-behinds. I try to import these files into another project and when I try to use these xaml controls in my main view file, Visual Studio cannot find the namespace that the imported xaml's and C# code-behinds are attached to.
I tried changing the namespace to be the same as my current project. I tried restarting Visual Studio 2013. Neither of these worked.
I tried adding the project with the custom controls to my solution. The imported project can read the custom xaml's, but my main project still can't reference them. I tried dragging the files over to the main project, and they still won't work.
I tried rebuilding the controls xaml's and C# code-behinds in my new project it still says:
The type 'local:ClickSelectTextBox' was not found. Please verify that that you are not missing an assembly reference and that all reference assemblies have been built.
This item is under the appropriate namespace and in the current project.
In visual studio go to TOOLS -> choose Toolbox Items. this will allow you either choose from an array of different components or browse around to find a dll that you would like to use.
EDIT:
Oh so you are trying to take customized xaml files that you already have written and modify them in a separate project? I would suggest one of two things.
1: right click your project name -> add existing, and add the xaml and xaml.cs file to your project at the same time.
if for some reason that does not work you can also try
2: creating a new xaml control (with the same name of the control you want to drop in) in your project and copy pasting the xaml code into that control, this should autogenerate the codebehind designer shell you are going to need. you can then go into the xaml.cs file and drop whatever business logic you are looking for. It is not the cleanest solution but sometimes the WPF editor gets a little funky when importing xaml files
I know it's an old post but still somebody may find it useful:) So! ... Make sure
1)You don't have public class outside of root namespace, check this
link
2)You are not mixing targets of your assemblies (unless you can't 100% avoid that)
For example, if you are referencing something like SQLite.Core NuGet (that has both x86 and x64 versions of SQLite.Interop.dll built in) in a project that is AnyCPU, sometimes it's easier to set application's target to x86 or x64 to solve the x86/x64 paths issues - but then you may get all these "type not found/control not built/assembly not found" and all that sorts of nonsense from Designer even despite your app builds and runs ok.
Hope that helps
Try downloading ReSharper's trial version, install it and then open up your code again. One of the awesome features Resharper has with XAML code is that it will automatically map objects to their appropriate namespace. I think this will make it easier for you and will show you a ton of ways to do things better. When I was first learning WPF it was honestly a godsend to use Resharper.

Devexpress xaf modules

Using devexpress 12.2.x
Lets say we create a cross platform application. SomeApp
The following projects are created:
SomeApp.Module
SomeApp.Module.Web
SomeApp.Module.Win
SomeApp.Web
SomeApp.Win
Now each of the .Module projects contains a xafml file.
So far I've only made changes in my SomeApp.Module project, but I've been wondering what would be the effect/purpose of making the changes in for e.g. SomeApp.Module.Win project. Basically whats the differences between those xafml files and when would I make changes in the one and not the other?
Refer to the Application Solution Structure
A application solution contains the following:
Windows Forms Application Project - Code, specific to the Windows Forms
version of your application.
Web Application Project - Code, specific to a browser-based interface.
Module Project - Use this assembly to implement UI-independent
application elements. For example, in it you can define a business
model. Subsequently, both the Windows Forms and ASP.NET Web
applications will have a similar business model.
Windows Forms Module Project - Use this assembly to implement
application elements for the Windows Forms application version. This
assembly is referenced in the Windows Forms application project only.
ASP.NET Web Module Project -
Use this assembly to implement application elements for the ASP.NET Web application version. This assembly is referenced in the
Web application project only.
Further Reading
XAF overlays the changes in the module difference files. The model applied to your application (that is, the model resulting from overlaying all the Model.DesignedDiffs.xafml - files in your modules) is the file Model.xafml in your main project(s) (SomeApp.Web, SomeApp.Win)
The question which adjustment should be made in which xafml-file is hard to answer. We have tried several solutions already, none is really perfect. A general rule of thumb could be: Adjustments to an element are applied to the xafml file of the module where the element is defined.
Sometimes, especially if you have a layered application, it could be that you will have to apply the same adjustment in two different modules (e.g.: Label of a data item on a product level could differ from that on a customer level) .
In Devexpress XAF applications have three main parts. Module, Module.Win.Control, Module.Win. Win.Control part include Module part and Win Part include Win.Control part.
So Model.DesignedDiffs.xafml files have same behavior.
If you change on module xafml, it affects other xafml files but you change win xafml file, it affects only itself. This structure is same like dll reference.

How can I share common style information (css, images, etc.) across MVC sites?

It's dead simple to share functionality across multiple MVC projects. You just put the code into its own project and reference it in as many solutions as your heart desires. Clean, standard, glorious.
Is there any means to do this for styling code? I'd like to have our common CSS files, the ones that give our applications a similar look and feel, in just one place. Right now I have to spawn new copies for every new application. Thus if something needs to be fixed, it needs to be fixed a dozen times in a dozen places.
Has anyone else dealt with this? I can't separate out the CSS files into their own project, nor do I really want to have a web application that's just css sitting somewhere so all of the applications can use the files remotely via fully-qualified Urls. Is there a TFS trick you can do with source control to link the files together? Is there something I haven't thought of?
Here is the "dead simple" solution for sharing web resources between projects without using CDN, LESS, SASS, NuGet, etc:
Create common Solution Folders containing the resources to be shared, or simply designate one of the projects to be the master.
Use "Add as Link" to add the shared resource files to each project as needed.
Add an AfterBuild task to each project file that will copy the linked files to project folders. This is only needed so that Visual Studio test/debug (F5) will work locally.
If you need the details on how to do this, keep reading.
Configuring Solution Folders for the Shared Resources
** Note that if you're simply going to share files directly from one project to one or more additional projects then you can skip this step.
Visual Studio solution folders do not have to reflect physical file system folders, but doing so will help preserve your sanity. So first create the folders on your local file system and copy the resource files into them. The new folders should be located under your solution folder. For example:
\MySolution
\Common
\Images
\Scripts
\Styles
Back in Visual Studio, right click on the Solution Items folder and use Add Solution Folder to replicate the new file system folders.
Next, add the files to the new solution folders by right-clicking each folder and using Add Existing Item to add the contents of the folders.
Add Shared Resources as Links
For each project that will use the shared resources, right-click the project folder and choose Add Existing Item. Browse to the common folder, select the desired files, click the drop-down arrow next to the "Add" button and choose "Add as Link".
You may get a source control warning about adding files that are outside of the project directory structure, but this can be ignored since the linked file will be under source control at its source.
Add an AfterBuild Task to Copy Files
When you publish the application to a server the linked files will copied to the project folders to which they are linked and everything works as expected. However, in the development environment the linked files do not physically reside in the project folders. So when you hit F5 to test your application in VS, the shared resources will be missing.
The simple solution is to add an MSBuild task to copy the linked files from their source after each build. This needs to be done to for each project that contains the shared resource links.
Right-click the project and choose Unload Project. Right-click the project again and choose Edit <ProjectFileName>. Scroll to the bottom and add the following (just above "</Project>"):
<Target Name="AfterBuild">
<!-- Copy linked content files to local folders so that they are available in the debugger.
This is only an issue when running the application locally. The linked files should
be automatically published to the correct folder when publishing to a web server. -->
<Copy SourceFiles="%(Content.Identity)"
DestinationFiles="%(Content.Link)"
SkipUnchangedFiles='true'
OverwriteReadOnlyFiles='true'
Condition="'%(Content.Link)' != ''" />
</Target>
** Copy task adapted from this link in TheCodeDestroyer's answer.
Save the project file then right-click and choose Reload Project.
Why not just have one site host that base styling and the other sites reference those styles? I don't see anything wrong with this.
You could create a CDN application of sorts to do this, too.
MVC App #1
<link src="~/css/styles.css" />
MVC App #2
<link src="http://mvcapp1.com/css/styles.css" />
Well, I don't know much about asp.net development, so forgive me, if it's not the case, but
If resource files in your project have Build Action set to None or Content and Copy to Output Directory set to Copy..., you can easily create the Class Library type of project and place all the files there (preserving the paths), and then reference this "Class Library" in every project that needs the files. Every file will be copied to every referencing project on solution build.
For Embedded Resource build action it will also work, but, you'll need to find a way to specify the assembly, which contains these files (because it will differ from Assembly.GetEntryAssembly).
Personally I don't like or want the CDN solution as if you have many pages they depend on CDNs 100% up time. After some research I found this solution which was perfect for my use I hope whoever will look for an alternative this is one of them:
http://mattperdeck.com/post/Copying-linked-content-files-at-each-build-using-MSBuild.aspx
1 - Look into CSS template systems as mentioned :
SASS-Lang
Less
http://css-tricks.com/sass-vs-less/ (really good article to start, many related items to in his related posts widget)
These allow you to code your stylesheets in organised manners. You can quickly add dynamic configurations and global changes easily.
2 - Developer your own CSS global listing system :
If you prefer not to use the above CSS stylesheet system. Example
//cdn.com/assets/css/reset.css
//cdn.com/assets/css/main.css
//cdn.com/assets/css/page_home.css
//cdn.com/assets/css/page_cart.css
even...
//cdn.com/assets/global/form_styles.css
//cdn.com/assets/global/global_shortcuts.css
In these, the same form padding, table and tr and other padding rules. Example
.black{color:#000 !important}
.right{float:right}
.left{float:left}
I know I sound like framework mentality but it works..
You can quickly alter the global to ensure all pages are updated.
The CDN storage and compass suggestions are valid too. You see storing on a CDN will save the headache of worrying about application failure / speed / load.
Your application can simply be like
/cloud/servers/settings/global/db
/cloud/servers/settings/global/librarys
/cloud/servers/settings/global/css_config.php (example)
/cloud/servers/1/webapp.com/
/cloud/servers/1/webapp.com/model
/cloud/servers/1/webapp.com/view
/cloud/servers/1/webapp.com/view/themes/tpl
/cloud/servers/1/webapp.com/inc
/cloud/servers/1/webapp2.com/
/cloud/servers/1/webapp2.com/model
/cloud/servers/1/webapp2.com/view
/cloud/servers/1/webapp2.com/view/themes/tpl
/cloud/servers/1/webapp2.com/inc
//cdn.com/assets/css
3 - Configuration of Approach
I personally think that the question should be about the approach of your overall development methodology. Having CSS sit on a CDN application, or having a CSS on a separate server which syncs to the CDN for production live mode is a good idea - keeping it separate and maintaining it via a stylesheet language is even better. You can then quickly use skins, css libraries, image libraries and more. Keeps things organised, faster and much better and ENJOYABLE to look at and take pride in coding with.
Keeping it and using a better system is what is needed. You should use manual and the classical approach of a folder structure IMO. You won't have to worry about responsive application design for mobile/tablet and other bearing issues with updating one CSS line for all the apps or even single apps - even languages, and dealing with multi site development teams.
JUST MY HUMBLE OPINION
Would also strongly recommend a CSS stylesheet language, sure many people hate them. But they are becoming quite useful, especially SAAS it's not a hype like NodeJS was.. it actually works. And does wonders. Look at TopShop, GorgeousCouture.. Arcadia sites.. multiple languages, multiple currencies.. servers and teams working on the same cross brand and several applications for each store..
We had the same problem and for our purposes we put all general CSS/JS/Images/Layout View into NuGet package and reuse it from every application where we need it. It perfectly works for us.
If you're open to using Sass, Compass extensions might be just what you need.
http://compass-style.org/help/tutorials/extensions/
An extension, when bundled as a gem, allows you to easily include the styles contained within the gem from anywhere on the system that has the gem installed. I recently used this in my latest application (a specialized multi-user CMS where each user has their own subdomain that has a customized layout, but all of the components/widgets have the same styling throughout the application). Setting up a new subdomain's styling is as simple as running a single command and customizing the template I've setup that has a skeleton of a simple layout.
Compass extensions can be used to hold images and JavaScript files as part of a template, but deployed files aren't automatically updated like the styles are (templates from a Compass extension differ from the stylesheets, as the templates are for copying and the stylesheets are for importing).

Sharing code between 2 projects without a dll

How can I have code-sharing between two projects without making a dll?
The issue is: I have a tool that syncs users & groups from LDAP to a database.
Now the tool is a windows service, but testing it as such is very difficult and time consuming.
Which is why I made a console application where I can test the LDAP syncing, and then just copy the respective sourcecode-files over to the service project.
But... keeping the common files in sync is a bit of a problem.
I don't want to make a dll, because this probably creates me a problem with
the 3rd project, a windows installer (for the service) where I have to use ExecutingAssembly path...
Is there a way to share the code without making a separate dll?
Automagic statical linking, so to say ?
How about adding a file as a link.
In Visual Studio right click on your console test app project -> select add existing file -> in the file add dialog navigate to files in your actual windows service project -> select the files you want to share -> and on add button select add as link option.
You can add a file to a project as a link. On the Add Existing Item dialogue the Add button has a drop down on its right. Use this to select "Add as Link":
Put the file as a solution item and add as a link to each project.
How about hand-modify the project files to point to the same source file?
Another option - put both projects in the same folder. Add a class to one, then in the other project add existing class and point to the class just created.
You could:
maintain the shared code in a separate project that produces a DLL and then use a tool such as ILMerge to turn the DLL & EXE into one assembly.
share the source-files between multiple projects, either by tweakiing your project files or doing something funky with your source-tree layout.
All that said, the best approach would be to bite the bullet and store the shared code in a shared assembly (DLL). What happens when you decide to, for example, expose this code via a WCF service? It starts getting more complicated then as you have 3 places that reference the same code files. Don't just think about what makes your life easiest now, think about what'll make your life (and that of anyone else who has to maintain the code) easier in the future as well! =)
Necromancing - As per Visual Studio 2017:
You can create a shared project, and then reference the shared project in another project.
It will use the framework-version and libraries from the project you reference the shared-project from. You can also use the same shared project in multiple projects, provided you get no conflict.
This is basically statical linking on a source-code level.
This also works with HTML&JavaScript-files (specifically, it works with publishing), but with HTML & JS files, you will run into problems while debugging...
It's under "Classical Windows Desktop", but you can also use it for .NET Core etc.
If you want to share functionality, you should use a DLL or similar.
Since what you want to share is the source, what you are essentially sharing is file sharing. So you can do that by making your projects reference external sources or you can have your source control do this for you.
If you are using Visual SourceSafe, you can make a link between two folders. VSS will make sure that they are treated as the same file.
I'm going to describe the setup we use to manage and test our Windows Service projects. While this doesn't answer the question of "sharing code without a DLL" (Unmesh's answer takes care of that), I think the OP probably doesn't realize how easy this is with a DLL. In any case, I'm hoping it will help someone.
Create a solution, LDAPSync. Create three projects in this solution:
LDAPSyncLib
LDAPSyncSvc
LDAPSyncTest
LDAPSyncLib is a DLL project that contains all of your business logic and main functionality.
LDAPSyncSvc is a Windows Service project that contains two classes, a service controller class that inherits from ServiceBase, and an Installer class for your service. This project has a "project reference" to LDAPSyncLib.
LDAPSyncTest is either a GUI application (WinForms, WCF, etc.) or a console application, depending on your needs. This project also has a "project reference" to LDAPSyncLib. Its sole purpose is to provide some interface which allows you to easily make the required calls into your business logic for testing purposes. In Visual Studio, set this as your "StartUp Project".
Now, when you run in debug via Visual Studio you will get a nice little GUI or command window that you can use to manually make test calls. When you install it as a Windows Service, the LDAPSyncSvc project's controller class will take over and handle all of the necessary service requests (start, stop, pause, etc.)
We have around 30 in-house Windows Service projects that we've been continuously managing, developing and testing for over a decade and this workflow has proved invaluable in quickly finding and fixing bugs when they arise. Best of luck with your project and I hope this helps some future Googlers.

Propagation of .config settings

We have a fairly hefty VS2008 solution that comprises of many library projects that are referenced by one or more other projects. Some of these libraries define things like WCF bindings and connection strings, but when these are referenced by other projects, it seems to become a necessity to copy the binding settings from the library projects' .config files into the executable projects. It seems like we're missing something here as this approach has started to violate DRY principals in a major way with duplicate settings littered throughout the solution. Changing a binding has become a major exercise in search & replace.
I have looked at the this project on CodePlex as a possible solution, but I wonder if we're misunderstanding the principals behind app/web.config files.
Is there an easier way?
Not really no.
In sufficiently large projects you end up with settings that need to go in several projects.
One solution I've used previously is to have a custom task run on post-build to modify the configs to set a specific variable (say '$generalSettings') with a bunch on common things, from a local file I call 'local.deploy.properties'. I use NAnt to do this.
These days, I use a custom solution I've written to do it (though it combines the approach above anyway, due to the need to test locally).
Anyway, what I'm getting at is this is a generally unsolved problem.
You have to automate settings propagation in order to keep things working properly. This can be done by adding batch copy command in post-build actions. You can find this settings in the project properties menu.
In order to customize copied settings for a specific project the XSLT transform can be used.

Categories

Resources