Playing sounds in WPF

I think playing sounds in a WPF could not be easier than this:

using

System.Media;

SoundPlayer

player = new SoundPlayer("Assets/type.wav");

player.Play();

And that's it :)

Accessing controls in DataTemplate for Listbox in WPF

Hello,

I've been searching around on how to access controls that are in DataTemplate for the listbox items in WPF and I came through this post that explained it all in an easy way.

Regards,

CSS Hassle for different browsers

Even been into the hassle of an HTML table displaying differently on different browsers ? of course every UI developer have been into it. I've found a very interesting solution to this problem.

Suppose that you have a CSS class called "TableLayout" and you want this class to have different attributes according to the client browser.

You only need to write it like that in the CSS file:

.ie .TableLayout

{

   margin-left: 15px;

}

.webkit .TableLayout

{

   margin-left: 0px;

}

This is very simple as it defines this class for Internet explorer to have a left margin of 15px, and for webkit browsers (like google chrome for example) to be with no left margin.

Final step is to include the following javascript into your page:

<script src="css_browser_selector.js" type="text/javascript"></script>

and that's it :)

For downloading the script go to this link

Cheers,

Preventing faulty callbacks to ruin your WCF service

Hello,

I had a problem in one of the tasks, that is when using callbacks with WCF service sometimes the callback faults and causes your service to hang or timeout the request.

The solution to this was to callback your client in a different thread and catch the exception, and then return it to the application in a nice way.

Here's an example for this:

private void YourMethod()

{

   //... Do work

   //Time to callback one of the clients

   

BackgroundWorker workerThread = new BackgroundWorker();

workerThread.DoWork += new DoWorkEventHandler(workerThread_DoWork);

workerThread.RunWorkerAsync(callbackObj);


}

static

void workerThread_DoWork(object sender, DoWorkEventArgs e)

{

ICallBackContract callback = e.Argument as ICallBackContr

try

{

   callback.CallClientMethod();

}

catch

{

   //Do your error handling then

}

}

Cheers,

 

WPF Notify Icon

Ever wondered how you can create a notify icon that is displayed in task bar and can popup some notifications in your WPF application ? If you do, here's an excellent project that can help you get your task done :).

Cheers,

WPF Themes

Hello,

I was developing the past days a WPF application and I've always dreamed about starting to learn how to create a wonderful looking application with animations and colors that may one day make it look like this famous hospital application that was introduced by the announcement of WPF in every event by Microsoft :) (here's a screenshot of it). So, I may not have reached the same look and nice animations, but I've found a very interesting project on codeplex that can make you theme your application in no time and continue designing it with your imagination.

Link to codeplex project

Cheers,

Set DispatchRuntime.AutomaticInputSessionShutdown to false "WCF Exception"

Hello everyone,

Been a while since my last post. I've had a weird exception that causes the WCF service proxy not to respond after a certain time (10 mins I guess), so thanks to this post I figured out the solution.

Solution that worked for me was to enable reliable session on the client application's config file and service host's config like this:

<reliableSession enabled="true" inactivityTimeout="00:20:00" />

and that lead to increase from 10 mins to 20 hours :)

Cheers,

Google Maps in .NET Problem

Hello,

I've been struggling with Google maps till I found that someone implemented a wrapper so that you can use Google Map as an ASP.Net user control which is a great effort indeed. You can download it from this link.

However, after using it for a while, I've found out that it is storing the Google map object only once in the session and getting it from there whenever needed which was a problem for me that when you update the map in some page, you'll find it updated on another page.

So, I've digged deep in the code and updated it so that it stores the map object with a unique identifier that you set it as a property in the user control object like that:

this.googleMapCtrl.ControlID = Guid.NewGuid().ToString();

You can download the updated control files from here.

(Sorry the link is expired, if you want it write your email in a comment and I'll send it to you)

Cheers,

Google map problem in jQuery popup

Hello,

I've been struggling around with an issue that seems to be very simple but it turned out to be a nightmare :D. All I wanted to do is to place a google map inside a jQuery modal popup. The problem that it wasn't displaying the map correctly, then after searching the problem, it turned out to be that google map could not be displayed in a hidden div, so the solution was to hide the div by adding a style to it as:

left: -10000px

And by using a popup like this one (Fancy box), you’ll get the map to display correctly J

Here's a Working example:

<html>

<head>

    <title>Map in FancyBox popup</title>

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

    <meta charset="UTF-8">

    <style type="text/css">

        #container

        {

            left: -100000px;

            position: relative !important;

        }

        #map_canvas

        {

            margin: 0;

            padding: 0;

            height: 500px;

            width: 500px;

        }

    </style>

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

    <script type="text/javascript" src="jquery.fancybox-1.3.4.pack.js"></script>

    <script type="text/javascript" src="jquery.mousewheel-3.0.4.pack.js"></script>

    <link rel="stylesheet" href="jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

    

</head>

<body>

    <a id="inline" href="#map_canvas">Open Map</a>

    <div id="container">

        <div id="map_canvas">

        </div>

    </div>

</body>


<script type="text/javascript">

    var map;

    function initialize() {

        var myOptions = {

            zoom: 8,

            center: new google.maps.LatLng(-34.397, 150.644),

            mapTypeId: google.maps.MapTypeId.ROADMAP

        };

        map = new google.maps.Map(document.getElementById('map_canvas'),

            myOptions);

    }


    google.maps.event.addDomListener(window, 'load', initialize);

    $("a#inline").fancybox();


    </script>

</html>

​​​​​

Cheers,

 

Adding "Last Page" link to Data Form Webpart

Hello,

I've been playing around with paging in data form webpart. I thought ( well someone actually asked me ) about how to add a "Last Page" link to the paging in the webpart. So, I've not tested it a lot, but it may help.

Add this xsl variable inside the ms-paging td:

<xsl:variable name="PagesNumber" select="ceiling($dvt_RowCount div $RowLimit)"/>

And add this anchor tag in the place you want it to be:

          <a>
          <xsl:attribute name="href">
          javascript: <xsl:value-of select="ddwrt:GenFireServerEvent(concat('dvt_firstrow={',$dvt_RowCount - $PagesNumber + 1,'};dvt_startposition={',$PagesNumber,'}'))" />;
          </xsl:attribute>

          Last Page
          </a>
 

Cheers,

«May»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789