How do I conditionally change properties of controls in the CellTemplate of a data bound WPF ListView?

Ok... I'm new to WPF, but I kind of know how to do things using DataTriggers and Converters.

But, what I want to seems a little more complex than that. Let me give you the details:

The DataContext for the ListView control is an IList of objects (object=Room). These are the available rooms. I've got another control (let's say it's a TextBox) that it bound to one of the Room objects contained in the IList. I want to display an image only for the room (ListViewItem) that is bound to the other control.

This is some of my XAML:

<TextBox Name="Room" />
<ListView Name="RoomsList" SelectionMode="Single">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="32">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <!-- 
                           Here's where I want to change the Source property
                           depending on whether or not the item matches the
                           TextBox DataContext.
                        -->
                        <Image Source="Images/Check.png" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Room Name" Width="150" HeaderContainerStyle="{StaticResource textHeaderStyle}" 
                DisplayMemberBinding="{Binding Path=RoomName}" />
        </GridView>
    </ListView.View>
</ListView>

I'm kind of stuck on this one. Any ideas as to how to approach this?

Answers


You can write a MultiValueConverter which returns Visibility back and takes DataContext as the first Converter Value and the specific 'Room' object as the second Value(Use ElementName binding with Element as 'Room') If the Values matches then show the Image control ie, imgControl.Visibility bind to the Converter


Need Your Help

IE isn't show favicon on 404 and 500 page only. What is may be wrong?

internet-explorer tomcat spring-mvc favicon

IE isn't showing favicon for 404 and 500 pages only. What may be wrong?

After closing popup window next page is opening in new tab

javascript jquery html popup struts

In my code, I need to open a popup window in which some work will take place. Then, the from the parent page I will resume working. The problem is that after closing the popup window whenever I am

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.