Sunday, April 3, 2011

Passing data from WPF tabs to a function

I have a WPF app with a single form containing some WPF tabs. Three of the tabs are used to collect data from the user. The last tab has an OK button and when clicked performs some calculations.

How to I pass data from the text boxes on the various tabs to the function located in the buttonclick event? I have the function created. I just need to know how to reference the values from the textboxes on the tabs.

From stackoverflow
  • Give the controls a name with the Name="myTextBox" attribute then Visual Studio or Blend will create identifiers for the controls in the code-behind for your form and you can access them via their names.

    void OKButton_Click(object sender, EventArgs e) {
       // string first = firstName.Text;
       // string last = lastName.Text;
       // etc.../
    }
    
    Scott : I thought that's the way it should work. After a reboot, my intellisense contained the textboxes and everything was fine.
    Will Eddins : If this worked for you, you make it your accepted answer.
  • If your textboxes have Name or x:Name attributes set on them in XAML, you can access them in your codebehind.

Algorithm to "smooth out" data values for visualization

I'm reading some data for countries around the world and am playing with Google's visualization gadgets, in particular the map visualizations. The problem is, that the US always comes out way in front. While most countries have values between 1 and 50, the US consistently has a value of 2000+. Which means in the visualization, it's hard to tell the difference between all the "small countries", as they all get about the same shade of pale green, while the US always is a fat dark green.

I don't particularly care about the accuracy of the visualization, so I'd like to smooth out or average out the values a bit so that there's a visible difference between the very-low, low and not-so-low countries. What's a good algorithm to do that?

A pretty simple problem, but I'm not a math guy at all. ^_^;;

From stackoverflow
  • How about displaying data on a logarithmic scale. That way a value of 10 translates to 1, a value of 100 translates to 2, 1000 translates to 3 and so on.

    deceze : There you go, learned what log() is good for. ;) Thanks.
    Jouni K. Seppänen : Note that 0 translates to minus infinity, which may cause problems. A practical trick is to take log(1+x) or log(0.001+x) or whatever works for you, or perhaps log(min(1,x)), log(min(0.001,x)), etc.

How to Escape Character in EL with JSTL tag?

I have this JSP code snippet:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<c:choose>
  <c:when test="${var1.properties[\"Item Type\"] eq \"Animal's Part\"}">
    <c:set var="cssClassName" value="animalpart" />
  </c:when>
  <c:otherwise>
    <c:set var="cssClassName" value="" />
  </c:otherwise>
</c:choose>

The JSP cannot be compiled by the server. However, if I remove the character "'" from "Animal's Part", it is compilable. I tried to escape it by using "\" character but it still gives me error.

Any suggestion/help is appreciated. I tried to avoid using scriptlet if possible.

Thanks.

EDIT: I managed to get it working (after posting to StackOverflow), posted as one of the solution in this question. I tried other solution posted before that (by Vincent and Eddie), however, unfortunately, none works in my environment, although I reckon that they might works in the answers' environment. Thanks.

From stackoverflow
  • try this

    <c:when test='${var1.properties["Item Type"] eq "Animal\'s Part"}'>
    
  • Use escapeXml="false" For example:

    <c:out value="${formulario}" escapeXml="false" />
    
  • You have two easy choices:

    <c:when test="${var1.properties['Item Type'] eq 'Animal\'s Part'}">
    
    <c:when test='${var1.properties["Item Type"] eq "Animal\'s Part"}'>
    
  • Hi, this is the solution that works in my use case:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    
    <c:set var="itemType"        value="${var1.properties[\"Item Type\"]}" />
    <c:set var="item_animalpart" value="Animal's Part" />
    <c:set var="item_treepart"   value="Tree's Part" />
    
    <c:choose>
      <c:when test="${itemType eq name_item_animalpart}">
        <c:set var="cssClassName" value="animalpart" />
      </c:when>
      <c:when test="${itemType eq name_item_treepart}">
        <c:set var="cssClassName" value="treepart" />
      </c:when>
      <c:otherwise>
        <c:set var="cssClassName" value="" />
      </c:otherwise>
    </c:choose>
    

CSS Help, Making Menu Fluid

I got some help with this menu earlier but have a different request now.

The menu works fine with fixed width but I would like the words to wrap ONLY on the top menu categories. I need to be able to have n categories and have the width be evenly distributed. Obviously n would be within reason (I am not going to have 50 categories) but I need to be able to add more and not worry about hitting my width limit.

Thanks for any help.

Link:

http://www.seth-duncan.com/Test/TestMenu.html

-Seth

From stackoverflow
  • For every top level menu item add the class 'heading' (or something similar).

    Then add the following CSS to your page:

    #menu li
    {
        white-space: nowrap;
    }
    
    #menu .heading
    {
        white-space: normal;
    }
    

Performance : encapsulating a string in a struct?

Hi,

Would there be any perforamce gain in ecapsulating a string in a lightweight reference object vs encapsulating a string in a struct. Would the string variable not utlimately point to the heap anyway , irrespective of whether it is contained within a value type or reference type?

From stackoverflow
  • The string is always located on the heap, so it wouldn't help. Putting the reference to the string in the struct can only make it slower, since it needs an extra derefence. But this won't be measurable in practice probably.

    If you really wanted a string to be on the stack instead of the heap, you would have to create your own custom strings as a struct containing chars. But that's going to be a lot of pain for no gain and can only be used to represent a fixed sized string since the struct is of a fixed size.

  • Since you tagged this one as .NET the string will most certainly be stored on the heap. However I don't think that there will be a noticeable difference and why should there be? First the object or struct must dereferenced and located and after that the string itself. It could be a plus, if you could do without encapsulating the string from a performance and a memory perspective.

Sample code for JSON-RPC client in C#

I need a simple JSON-RPC 1.0 client in C#, preferably using .NET 2.0 or later. I checked out JRock 0.9 They have several samples including Yahoo reader, but the samples demo JSON, not JSON-RPC. I understand I could implement RPC part using any of the available JSON parsers, like JRock or two from Microsoft. I would prefer a ready sample.

From stackoverflow
  • 2 Samples here

    There are two different implementations. Read the whole thread + check the attachments

ASP.NET Authentication with Roles in IIS7 Integrated Mode for Static Content

I am experimenting with the integrated authentication mode for static content in IIS7. I followed the instructions in this article: http://aspnet.4guysfromrolla.com/articles/122408-1.aspx It is working fine if I allow/deny access by login status (like in the article). However I want to allow/deny access based on roles (using the ASP.NET built in Roles Provider). When I put an allow rule for the role "Admin" in the web.config and deny rule for all other users I am not able to access the static files even when I login as an admin. The same folder contains non-static content (aspx pages) that are accessed just fine based on the Role Provider information.

Any ideas?

From stackoverflow
  • I would say the most likely culprit is that the static files are not being processed by ASP.NET but being left up to IIS.

    Does it work if you add a wildcard script mapping?

    Stilgar : what do you suggest to add as a wildcard script mapping? and if this is the case why does the authentication based on login status work but not the roles?