WPF: Inherit Style From Style. BasedOn Is Your Friend
- Sean
So another quick one. Say you have a style for creating round buttons, but you don't want to include a size, how a size be applied without touching the original style? Well you could just adjust the properties right on the button, but what if you want something a little more reusable? It's actually pretty simple, just have one style "inherit" the other. Well that's where BasedOn comes in.
Say you have a style named RoundButton.
<Style x:Key="GlassButton" TargetType="{x:Type Button}"> ... </Style>
All you have to do is create a new style:
<Style x:Key="HeaderButton" BasedOn="{StaticResource GlassButton}" TargetType="{x:Type Button}"> <Setter Property="Height" Value="20" /> <Setter Property="Width" Value="20" /> </Style>
As you can see, it's pretty simple using the BasedOn keyword. Now when the HeaderButton style is applied to the button, it will take on the properties of the RoundButton style and the HeaderButton one. Nice huh?
WPF: Hide Built in Header Bar For an Open Window
- Sean
Ok so this one is a simple one. Well at least once you see it in action. Say you want to get rid of the built in windows header bar:
You know, that thing. Well it's crazy simple. And I mean crazy as in mind boggling, not crazy like dress up your cat in clothes crazy.
All you have to do is set these two properties:
AllowsTransparency="True" WindowStyle="None"
In the window tag at the top of the page. For example:
<Window x:Class="DesCombine.WPF.FileUpload" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="File Upload" Height="350" Width="525" BorderThickness="0" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" AllowsTransparency="True" WindowStyle="None">
Only catch is that you have to now supply any useful buttons like Minimize or Close by yourself. But I never said that you wouldn't. You thought that. You.
Spark View Engine, ASP.Net MVC, and You
- Sean
So one of the things I was forced to use, semi kicking and screaming, at one point in my illustrious career was the Spark View Engine for ASP.Net MVC. Actually that's not totally true. I only kicked for a bit then skipped the screaming once I noticed what it did: It took all the ugly <% %> junk out of the html... my beautiful html... and made things like for loops much nicer. Mind you, this is mererly the tip of the ice pick... eh berg I meant berg... there's a lot more to it. It handles things like Master Pages and Partial Controls pretty darn well as well as caching javascript files on the go. Sounds good? Well it should and if it doesn't, I don't think we can be friends.
First off, I just wanted to quickly write something up on how to get it all going and because I'm such a nice guy I even have a project that is ready to go for common use. The catch is that I made it in 2010 so if you don't have that yet, you could be screwed. Then again I could type out a lot of the steps too. You just don't know.
First off you can either get the assemblies from my hosted project, or you can go here and get it. Either way, I don't care. No really, I don't. Not just sayin'. The care cup had run dry.
The two assemblies you need to reference in your project are:
spark.dll spark.mvc
Next add this line to the Application_Start method in the Global.asax.cs file:
ViewEngines.Engines.Add(new SparkViewFactory());
After that, you'll have to add a little somethin' somethin' to your web.config. I know, I know. This is all so very hard. Live strong like Lance.
<configuration> ... <configSections> <section name="spark" type="Spark.Configuration.SparkSectionHandler, Spark"/> </configSections> ... <spark> <compilation debug="true" defaultLanguage="CSharp"> <assemblies> <add assembly="PhotoShare.UI" /> //Whatever the actual UI project is </assemblies> </compilation> <pages automaticEncoding="false"> //If you want it to auto HTML encode post/get stuff <namespaces> <add namespace="System"/> <add namespace="System.Collections.Generic"/> <add namespace="System.Linq"/> <add namespace="System.Web.Mvc"/> </namespaces> </pages> </spark>
Ok so the web config is ready. Now what?
Well now you are going to create a master page. That's right you are. Don't fight me on this. I'm way cooler than you.
There is a little directory structure hard coding going on since by default you have to have things in certain places for Spark. Oh well. All Master Pages go in a directory named "Layouts" in the "Views" directory. So something like:
Views/Layouts/Application.spark
D--- it. Forgot about that little tid bit too. Spark files have to be named .spark. Well actually I think there's a way to call them whatever you want, but lets just go with defaults for now smarty pants.
And for the hard part, the html for the master page.
<html> <head> </head> <body> <div> <use content="Middle" /> aasdfasdfa </div> </body> </html>
HOLY HECK THAT'S HARD! Now there needs to be a controller. So just create one in the controllers folder. In my project it's called this:
Controllers/SparkTestController.cs
And then go ahead and create a view for index. Once you've done that, rename the extension from aspx to spark. Now for the html:
<use master="Application"/> <div> <content name="Middle"> hi there </content> </div>
And that's it really. As you can see, the placeholder on the master page (use content="Middle") is referred to on the child page.
To make testing this page easy, I would suggest changing the routing in the Global.asax.cs file to:
routes.MapRoute(
"Default",
"{controller}/{action}",
new { controller = "SparkTest", action = "Index"}
And you should see something like:
hi there aasdfasdfa
Proving that both the master page and the child page are printing stuff out.
You might be wondering why you should do all of this? If you aren't, you are one hell of a lemming. And not the cool kind like those little guys that blow themselves up for the betterment of the lemming collective. You're that stupid one the just sits there with its hand out shaking its head.
A quick example:
<% if(something.IsTrue) { %> <div> hihihihih </div> <% } %>
Compared to:
<div if="something.IsTrue"> hihihihih </div>
Small example, but I think its pretty obvious why the second is so much better. And this is just scratching the surface on what spark does really. I'd suggest looking here for more. I'd also suggest a new hair cut because... just wow.
ByATool.com Is Looking For Writers
- Andre
Yeah, you read that right. ByATool.com is looking to add one or two writers with various IT backgrounds. This is not a job, it is simply an avenue for you to get your work read. We want to know what YOU want to write about. It's no fun to be given a topic to write about when your passion lies elsewhere. Please contact us at the address listed below so we can discuss this one-on-one!
What we need from you:
Name:
E-Mail:
What would you like to write about:
How often would you like to write:
Please submit this simple information, along with an example blog post to iwanttowrite [at] byatool [dot] com
New SharePoint Server Explorer in Visual Studio 2010
- Amy
Just kinda geeking out about this, but when looking over some of the new features for Visual Studio 2010 I caught this little gem in the white paper….
You see that?.... IT’s A SHAREPOINT SITE IN THE SERVER EXPLORER!!
<Rubs hands together gleefully> Now… to figure out how to fit playing with this in after all my other urgent priorities….
MVC and Table Inheritance: Part 1
- Amy
PART 1: Setting up the database and Entity Framework Model
Okay, so say you need to create an internal IIS hosted web application that acts as a portal for managing internal training courses. You could do a simple ASP.NET web forms app.... but what's the fun in that?!? Besides, you know that you're going to need to expand this thing regularly to handle different course types and provide different layers of permission depending on the user. Well, as it happens, ASP.NET MVC is a really nice way to address such a situation (especially if you're already familiar with using Java and Struts).
Before we get started you'll need to get the usual downloads from Microsoft found here: http://www.asp.net/mvc/
Create ASP.NET MVC Project
Then you'll need to open either Visual Studio 2008 or the free Visual Web Developer 2008 Express and select the File->New Project menu item. This will bring up the "New Project" dialog. To create a new ASP.NET MVC application, we'll select the "Web" node on the left-hand side of the dialog and then choose the ASP.NET MVC Web Application template and enter the following:
- Name: TrainingPortalMVC
- Location: C:\Development
- Solution: Create new Solution
- Solution Name: TrainingPortalMVC
- Create directory for solution: checked
SQL 2005 Database Tables
To setup your MVC project so it can use the Microsoft Entity Framework:
- Right-click the App_Data folder in the Solution Explorer window and select the menu option Add, New Item.
- From the Add New Item dialog box, select SQL Server Database, give the database the name TrainingPortalDB.mdf, and click the Add button.
- Double-click the TrainingPortalDB.mdf file to open the Server Explorer/Database Explorer window.
- Click on the Database Diagrams folder and say yes to create a new diagram
- Setup your tables to look like this:
Create the Entity Framework Model
Steps
- Right-click the TrainingPortalMVC project.
- Select in the menu Add New Item
- Select from the Templates: ADO.NET Entity Data Model
- Enter the name TrainingPortalEDM.edmx then click Add
- Choose the Generate from database then click Next>
- For the data connection, select TrainingMvc.mdf make sure the checkbox is checked and the connection settings is TrainingMvcEntities then click Next>
- Check all tables in the database except for the sysdiagrams (dbo) one and make sure the Model Namespace is TrainingMvcModel. Click Finish
Suggested Modifications
- Open the ModelBrowser panel in Visual Studio 2008, and expand the EntityContainer->EntitySets and add “Set” to the end of your Entity Sets….. Trust me, it will make things much less confusing later…
When you're done you should have something like this:
This is the end of Part 1...... Calm down, I know you can't possibly wait for more answers, but a girl's gotta have a little mystery to keep things interesting. Good luck and hopefully this will help you shed another angle of light to get a better idea of how you want to approach this type of application until I can finish procrastinating.... I mean preparing Part 2.....
Failure scanning CollectionGen.dll for extensions.
- Sean
Quick hit, you might get this if you try loading the bin directory of the nantcontrib project AND YOU DIDN'T FOLLOW THIS POST.
Solution, FOLLOW THIS POST or you can simply remove the CollectionGen.dll from the bin directory. However if you do that, you aren't helping my bounce rate and that makes you a Communist... unless you are a Communist then it makes you a Capitalist.
How to Install/Using NantContrib BECAUSE THE DOCUMENTATION SUCKS
- Sean
I understand I'm not what you call the sharpest bulb in the bunch, but readmes shouldn't be painful. They should be helpful. They should be kind and gentle, and remind you that the world is great and wonderful. Not put you on the verge of a three figure body count. In a way, this is why I've shied away from a lot of open source stuff since the readme files read like instructions for putting together something from IKEA. And not the horrible broken English ones, more like the ones with all those funny squiggly lines. (I think it's call "Chinese") Why is it always so painful to figure something out WHEN YOU HAVE INSTRUCTIONS? Best hint on writing instructions, always assume the person you're writing to is an idiot. You can infer from that whatever you want.
Anyhow, NantContrib, the library of things that adds on to Nant (With brilliant ideas like being able to add an else to an if WOW), is a victim of nothumanenoughtowriteadecentreadmefileinawaythatnormalhumansunderstanditis (Otherwise known as Thoreau Syndrome) so I thought I would save you some together time between your head and your monitor.
Now you could go download it from wherever it is, or you can just grab this which is nantcontrib post "fixing" it. Basically if you get my version, all you have to do is drop it somewhere, anywhere, and extract. I put it in the same directory that Nant is, so they sort of sit side by side but separate. A happy little couple, at least for the first few years until Nant has a mid life crisis and decides it's time to get a Corvette and start rolling for college girls at which point nantcontrib starts eying the Fedex guy. Right now, its idealistic bliss.
Once you've done that, all you have to do is drop this bit into your nant script, probably above your properties, but it possibly can go other places. I haven't really looked into that.
<loadtasks>
<fileset>
<include name="c:\nantcontrib\bin\lib\" />
</fileset>
</loadtasks>
And now you are ready to go.
Now you might be curious about what I did to the directory structure of the nantcontrib stuff. It's actually pretty simple. I just took the bin folder and split it up. (Something I kind of pieced together from random pages) I took what I understand to be the important stuff (All the dlls except CollectionGen.dll and SlingShot.core.dll.. wait I'm sorry SLiNgshoT.core.dll cause f---ed up casing means its that much better. ITS HARDCORE MAN! TO THE XXXXXXXTREEEEMEEEE!) and put it into a new folder "lib" that still resides in the bin folder. The rest of the stuff went into a new folder "tasks". Then I had the loadtask command include everything in bin\lib. Boom, everything works as it should.
Force Embeded Video Behind A JQuery Modal Dialog
- Sean
Another quick one, [insert joke about sexual performance... HAHAHAHEHARHAHRAH] and I'll probably file this under "I don't care you if need this but I'm posting it because I have a bad memory". When you use the jQuery Modal Dialog with an embedded video, like say something from youtube, and you have a modal dialog on the same page, you might notice that the video stays in front of the dialog. This would be considered contrary to design. Nice thing is, it's an easy fix:
<object class="nospace" data="http://www.youtube.com/v/jU_lNNwCLp0&hl=en_US&fs=1&" height="320" type="application/x-shockwave-flash" width="400" > <param name="movie" value="http://www.youtube.com/v/jU_lNNwCLp0&hl=en_US&fs=1&" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always"/> <param name="wmode" value="opaque"/> <----- RIGHT THERE LOOK SEE IT????? </object>
It's the last parameter in that block. I posted the whole thing because it just seemed easier.
Element ‘Embed’ Is Not Supported: Embedding YouTube Video Without The Embed Tag
- Sean
This should be quick, so don't expect my usual charming self. If you've run into this problem, and chances are you have, you're probably as frustrated as a thumbless hitchhiker. Good thing is, I have the solution and you can watch it here on video:
HAHAH THAT WAS FUNNY! Yeah I'm not that big of a bag. I actually will give you the code. Go figure.
<object class="nospace" data="http://www.youtube.com/v/jU_lNNwCLp0&hl=en_US&fs=1&" height="320" type="application/x-shockwave-flash" width="400" > <param name="movie" value="http://www.youtube.com/v/jU_lNNwCLp0&hl=en_US&fs=1&" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always"/> </object>
And there it is. Easy as something other than pie because pie isn't f---ing easy to make.






