GTK+ Glade and CSS - c#

I've made a simple glade UI file for my programm. It contains of 2 textfields and 1 button. And also I made a css style which contains 1 button class named "button". When I added this file in Glade as "Custom CSS provider" it changed my button style within the editor.
After that I created the UI using GtkBuilder (I am using GTK# 3.20 bindings + C#).
Builder b = new Builder ();
b.AddFromFile ("login.xml");
b.Autoconnect (this);
It created my simple form (2 fields and 1 button) but there is no CSS Style applied to it. So I checked XML code of my UI file and found out that there is no reference to CSS exept of this:
<style>
<class name="button"/>
</style>
After that I read that I need CssProvider. So I created one.
CssProvider css = new CssProvider ();
css.LoadFromPath ("ui_common.css");
But nothing happened. So, how should I apply custom CSS to my Builder UI?

You are almost there; the last step is to take the GtkCssProvider and add it to a GtkStyleContext.
Since you are using a .ui file and a .css file, I assume you want to make your CSS apply to all widgets in the application. In that case, you can use gtk_style_context_add_provider_for_screen(), passing gdk_screen_get_default() as the GdkScreen. (This should be safe; it's what the GTK+ Inspector does. IIRC there was a more specific reason why this should be safe...)
You can also do this to individual widgets using gtk_widget_get_style_context() and gtk_style_context_add_provider().
In both cases, use GTK_STYLE_PROVIDER_PRIORITY_APPLICATION as the priority for application-local CSS.
(I do not know the C# names; sorry.)

Related

Stop CSS inheritance

I have a Blazor component, which I want not to be afected by the General Styles of the projects that use it.
The main problem is that the project that implements this Component, overrides some of the styles in their general styles.css, and it breaks the layout (principally because their project overrides some Bootstrap names).
I have been searching and found the CSS property all:revert; that I could add it to the first line of my component styles like this:
* {
all:revert;
}
So all the previous code that was modifying the component won't affect it.
But I'm not sure if this is the best solution to this problem.
Any help is appreciated.

How can I separate `<style>` from `<Window.Resources>`?

I have a lot of <Style> in <Window.Resources>.
How can I separate <Style> from <Window.Resources>?
Do I have to make a new Window file and use <Application.Resources>?
I also have a lot of those.
in my <Window.Resources>. Is it also possible to separate those?
You add those styles in ResourceDictionary and use it where ever required. You can add application level or Window Level.
http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/03/creating-and-consuming-resource-dictionaries-in-wpf-and-silverlight.aspx
http://www.codeproject.com/Articles/35346/Using-a-Resource-Dictionary-in-WPF
You can create a ResourceDictionary file. It's just a xaml where you can put styles, control templates etc. See here for more info: http://msdn.microsoft.com/en-gb/library/cc903952(v=vs.95).aspx
You can then attach this dictionary to your project in app.xaml.

aspx c# code behind not recognizing controls

I created a child template from visual studio to manage my kentico template. The template worked fine except that all the controls in it is not accessible from code behind because it is not recognized. I have checked for on line solution but none solved the issue. I even got this link
Codebehind file doesn't recognize aspx-controls
without any luck since I can't even access the myfile.aspx.designer.cs.
What do I trie again?
Note: My controls are not inside any panel or other control. Just inside a normal div.
Try adding runat="server" to your id tag.
Here is an example.
<tr class="headerrow" id="tbrHeader" runat="server">
I am unfamiliar with Kentico, but this is what I have come up with as possible solutions without having seen your code:
Make sure all your controls have a 'runat' attribute: runat="server". I am not trying to insult your intelligence, but it is an easy thing to forget(As I have done before), without this the control won't be recognised from code-behind
If it is a template file, have you made sure the codebehind that refers to it, is the code-behind of the template file, as the codebehind of other pages will not be able to find the control in the template without you telling them where it is.
With your new comment on the question: If your class is abstract, have you tried wrapping it in a non-abstract class? (source: stackoverflow.com/questions/481305)

Printing html file with pagebreaks

I am trying to create a program / service that can read an html file and print it.
I need to include page breaks; but don't know how to define them or make them print correctly.
The html files are mine, so I can add any elements to them to represent the page break position. I was thinking a hidden field, or using the page-break-before:always css style in the next element.
How should I approach this?
Css is the way to go. I'd recommend to create a class "page-break":
.page-break { page-break-before: always; }
Whereever you add this class to an HTML-element you get a page-break before this element (e.g. before every h1).
This tutorial covers almost every part of CSS and printing:
http://coding.smashingmagazine.com/2011/11/24/how-to-set-up-a-print-style-sheet/
hope this helps

SharePoint AJAX C# web part - visual layout of UpdatePanel controls

I'm creating a SharePoint web part in C# that is using an UpdatePanel for some AJAX magic. Everything is working fine, but I'd like to know how to lay out my controls visually (without using SharePoint Designer). I just have two dropdownlists, some labels, a button, and a textbox. I am creating them within the overridden CreateChildControls. Thanks!
add a container panel around your controls and give it a class. Add the panel to the UpdatePanel's container. Add all other controls to the new Panel's Controls.
You can now use css to do your styling, using the container panel's CssClass as reference.
in code:
protected override CreateChildControls()
{
// .. creation of updatepanel, say upd1
Panel container = new Panel{CssClass = "webpartContainer"};
upd1.ContentTemplateContainer.Controls.Add(container);
container.Controls.Add(dropdown1); // etc. etc.
}
The Css:
.webpartContainer
{
/* if needed add some style here also */
}
.webpartContainer select
{
/* add style */
}
.webpartContainer .specificClass
{
/* give controls a class of their own in CreateChildControls
if controls of the same type need different styling
(i.e. you have more than 1 select that need to look different) */
}
there are a couple of ways you can lay them out. you can add a Table object and add rows, cells, etc. and add your controls to the cells.
Alternately, you can override the RenderContents method and output HTML directly to the write that is passed in as a parameter. If you do this method (its probably less work and more efficient then using the Table objects), you should use a StringBuilder to build your HTML then output the results to the writer. This method should gain you some performance.
Sadly, there is no visual WYSIWIG editor for this method.
Unfortunately, there is no visual designer for web parts that are created programmatically.
You can use a user control and the SmartPart web part from codeplex to gain advantage of the visual designer for .ascx user controls.
You can use ASCX files in web parts.. just load it from your webpart class in CreateChildControls like so:
var control = Page.LoadControl("/_CONTROLTEMPLATES/yourproject/your.ascx");
Controls.Add(control);
This way you can use the normal way with Visual Studio to layout your webpart. Much nicer than building HTML in code which is a pain to say the least.
(this is also much better than using SmartPart which causes issues with the trustlevel and deployment)

Categories