WPF Listbox Disable Selection

While developing in WPF

I Browsed through the web to get the solution to the problem I was facing today, the problem was that I wanted to disable the selection of WPF Listbox,

I found multiple solutions to that

1. One solution was to use ItemsControl instead of Listbox but the customization of look and feel stopped me to use that solution.

2. The other solution recommended to update background of the ListBoxItem using trigger, I thought this solution would work but it didn’t worked for me. But I still it can work for many other facing the same problem.

This is how I did it


<ListBox.ItemContainerStyle>

<Style TargetType="{x:Type ListBoxItem}">

<Setter Property="Background" Value="Green"/>

<Style.Triggers>

<Trigger Property="IsSelected" Value="True">

<Setter Property="Background" Value="transparent"/>

</Trigger>

</Style.Triggers>

</Style>

</ListBox.ItemContainerStyle>

3. The third solution was to update the selection brush color so that it feels selection is disabled. This is how we achieve it


<ListBox itemsSources="{Binding Test}">

<ListBox.ItemContainerStyle>

<Style TargetType="{x:Type ListBoxItem}">

<Style.Resources>

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="transparent" />

<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"  Color="transparent" />

</Style.Resources>

</listBox.ItemContainerStyle>

</ListBox>

4. The final solution that I chose for my self was to set the IsFocusable property of Listbox item to false like this


<ListBox itemsSources="{Binding Test}">

<ListBox.ItemContainerStyle>

<Style TargetType="{x:Type ListBoxItem}">

<Setter Property="Focusable" Value="False"/>

</listBox.ItemContainerStyle>

</ListBox>

This wraps up the solutions in my knowledge.

Advertisements

Complete Cassandra guide for Cassandra beginners with PHP Demo App

Complete Cassandra guide for Cassandra beginners.
So for the past few days I had been trying to get Cassandra running on my PC, I looked upon a lot of resources, got the help but couldn’t get a test app in PHP so decided to make one. Now I have made that test Application so I think I must share this with you.
But before this we must have a little knowledge of Cassandra. So
What is Cassandra?
From Cassandra’s Wiki
Cassandra is a highly scalable, eventually consistent, distributed, structured key-value store.
Yes Cassandra is a nosql solution to save your data in hash maps. It not a traditional relational DBMS rather it is an alternative to Relational DBMSs like MySQL, SQL Server, Oracle, Postgresql and many others.
Who Uses Cassandra:
To get a fair idea of the power of Cassandra I think I must share with you some of the Users of Cassandra. Here is the list
• Facebook
• Digg
• Twitter
• IBM
• Redit
• App Scale
How to get Cassandra Running on Windows:
Pre Req: java must be installed and value of the environment variable “JAVA_HOME” must be set to its JRE Directory (in my case it is “C:\Program Files\Java\jre6”)
1. Get the latest binaries from http://cassandra.apache.org/download/”
2. Extract from Downloaded Archives to a folder say “Cassandra”(I’ll use this name in future)
3. Make three New Folders anywhere in your directory structure with names commitlog, data, saved cache.
4. Go to extracted archive and navigate to folder named “conf”
5. Open the file named “cassandra.yaml” in your favorite text editor.
6. In the “Cassandra.yaml” Set the values of
“data_file_directories” to the path of newly created “data” folder.
“commitlog_directory” to the path of newly created “commitlog” folder.
“saved_caches_directory” to the path of newly created “saved cache” folder.
So my values in “cassandra.yaml” look like this:
data_file_directories: C:\cassandra-data\data
commitlog_directory: C:\cassandra-data\commitlog
saved_caches_directory: C:\cassandra-data\saved cache
7. Add new environment variable “CASSANDRA_HOME” and set its value to the path of your Cassandra folder (Google to
know how to set environment variable).
8. Open cmd and navigate to the bin in your “Cassandra” folder
9. Run this command here “cassandra.bat”and your server will be running.
10. Open another cmd and run the command “Cassandra-cli –h localhost” and this must connect to your Cassandra
server.
11. If you see a message like “Connected to: Test Clusrer on localhost/9160” you are with me up till this point and
your Cassandra is running perfectly.
12. Run these commands on your client one by one
• Create keyspace testApp;
• Create column family Users;

Cassandra Data Model:
To understand how Data is actually modeled in Cassandra I would recommend you to go through these links.

http://arin.me/blog/wtf-is-a-supercolumn-cassandra-data-model
http://www.divconq.com/2010/how-to-add-and-retrieve-data-from-a-cassandra-database

My PHP Test App:
Note: From here this article assumes that you have average knowledge of PHP.
Cassandra offers different high level clients to interact with Cassandra for different technologies. You can have a look on these here: http://wiki.apache.org/cassandra/ClientOptions

My Test Application is developed using “PHPCassa” a high level client for PHP. What you need to do to run this app is fairly simple.
Pre Reqs: PHP Development Environment must be installed (xampp is recommended).
1. Download my source code from: https://sourceforge.net/projects/phpcassandra/files/
2. Extract from the archive anywhere in your directory structure.
3. Copy this folder to the www root of apache server i.e. the htdocs directory(in my case its C:\xampp\htdocs\).
4. Run Index.php in the application folder from your browser.
5. And you are all done.
Note: Application is coded very simply, I don’t feel any average PHP Programmer should have any problem
understanding the code.
Any Queries or Problems?
You can ask right here in the comments. I’ll try to answer the question within my domain of understanding.