Archive for the ‘WPF’ Category.

How Do I Center Something In My ListView Column?

So the items in your ListView column look like this:

Centered Example 1

And you want them to look like this:

Centered Example 2

If you’re trying to center something within a ListView column, it’s actually pretty simple.

Continue reading ‘How Do I Center Something In My ListView Column?’ »

MarkupExtension

Over at nostatic.com, there is an example of <a href=”http://notstatic.com/archives/118″>using MarkupExtension</a> that that we can access some custom code functionality directly from the XAML.

 In his example, the following XAML accesses a random number generator within the code.

<Button>

   <Button.RenderTransform>

      <RotateTransform Angle="{l:RandomNumber Min=0, Max=360}" />

   </Button.RenderTransform>

</Button>

Pretty cool. Apparently it only works when it isn’t placed inside a template… which makes it of limited usefulness, but still pretty neat.

Ellipsis and TextWrapping in a ListView Column

In response to the questions:

How do I make it so that, instead of cutting off the text in my column when I shorten it, my text displays ellipsis?

and

How do I make it so that my text wraps when I shorten my columns?

I’ll deal with the first one first and the second one… second.

That sounded better in my head than it looks on the screen.

With the first question… when a column is shortened, this is what normally happens:

CellTemplate Default Text

And, instead, we want this to happen: 

CellTemplate Ellipss

Continue reading ‘Ellipsis and TextWrapping in a ListView Column’ »

How do I connect an RSS Feed to my ListView/ListBox/Whatever?

When I’m doing the initial design for a project (while the developers are working on silly things like data validation and security), I often find myself in need of data so that I can see my project in action. The developers, of course, have no interest in conjuring up test data at that phase in the project, so I started using RSS feeds as data sources for my initial designs.

Not all RSS feeds are equal in the eyes of Blend. I use one of the New York Times RSS feeds, which always work flawlessly.

So we’re looking at the listview/listbox/whatever in our project. Right click on it (in the composition or in the Objects and Timeline pane, it doesn’t matter) and select the “Bind ItemsSource to Data”.

ItemSourceMenu

Continue reading ‘How do I connect an RSS Feed to my ListView/ListBox/Whatever?’ »

ListView FAQ

Please feel free to post additional questions in the comments section. I’ll get to them as I can and then link the help here.

That’s all I got for now. Ask me some questions if you want more stuff.

If you’re looking for something more generic, check out my WPF Designers Guide to the ListView, which covers the broader topics in the ListView.

Getting the Popup to Close When It Loses Focus

On a recent project, I spent (I kid you not) over three hours trying to get a stinking popup to close when I clicked somewhere else in the application.

 Figuring it was a focus issue, I tried the following triggers:

  • IsFocused
  • IsKeyboardFocused
  • IsKeyboardFocusWithin
  • IsMouseCapture
  • IsMouseCaptureWithin

All to no avail.

Turns out that the only thing I had to do was set the StaysOpen property of the Popup thus:

<Popup StaysOpen=”False>

Handy little property. I just wish that it was the default.

WPF Contest… Everyone Look Away Now

There is a WPF contest over at Lab 49 on visualization in the financial sector.

“WPF technology has the potential to revolutionize the visualization of data in the financial services industry and we’re looking for the best examples of WPF working with financial data that we can find to illustrate this.”

The prizes are pretty cool, but I’ll never be able to win anything if other people enter, so everyone stay away.

The WPF Designer Guide To Styling the (your-favorite-adjectival-swear-word-here) ListView

So, after months of delay I finally figured that there are probably some people out there who want to figure out how to make the WPF listview look the way they want it to look.

A quick note: I will be dealing almost entirely with the listview look. If you want the listview to do something (functionality) or look a certain way and you can’t find the answer here, leave a comment with your suggestion and I’ll try to blog about it and place a link to the answer in my listview FAQ.

My goal is to create a significant repository on getting the stinking listview to look the way you want and do what you want it to do.

You’re probably here because, compared with most of the WPF controls, Blend gives very little guidance on how to deal with the listview (even though you use the listview for practically everything you do).  So we’re going to start with the basic structure of the listview. This is what the basic listview looks like in the XAML.

<ListView>
     
<ListView.View>
           
<GridView>
                 
<GridViewColumn Header=”Column Header/>
           
</GridView>
      
</ListView.View>
</ListView>

So this post will start out giving basic guidance on what to edit when you’re trying to edit the various parts of the listview. I will update these sections with links and tutorials on listview specific tasks as time goes on.

Continue reading ‘The WPF Designer Guide To Styling the (your-favorite-adjectival-swear-word-here) ListView’ »