tags:

views:

68

answers:

1

well , seriously guys i got sick of WPF errors and hard handling , look i got many buttons are dsigned to represent rooms and i want to bind into a tooltip to get occupier name and informations from database . i cant find how to do it. Thanks

+2  A: 
  1. Build a RoomViewModel class that exposes Description, IsAvailable, OtherInformation, and other properties and implements INotifyPropertyChanged. How you populate these properties is up to your application.

  2. Build a RoomsViewModel class that exposes an ObservableCollection<RoomViewModel> named Rooms.

  3. Create DataTemplates for the RoomViewModel and RoomsViewModel classes (see below).

  4. Create an instance of the RoomsViewModel class and populate its Rooms collection.

  5. Create a ContentPresenter and set its Content property to the instance of your RoomsViewModel class.

Typical data templates might look like this:

<DataTemplate x:Type="{local:RoomsViewModel}">
   <ItemsControl ItemsSource="{Binding Rooms}">
      <ItemsControl.ItemsPanel>
         <ItemsPanelTemplate>
            <WrapPanel/>
         </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
   </ItemsControl>
</DataTemplate>

<DataTemplate x:Type="{local:RoomViewModel}">
   <Button 
      Margin="10"
      IsEnabled="{Binding IsAvailable}"
      ToolTip="{Binding OtherInformation}"
      Content="{Binding Description}"/>
</DataTemplate>

Future enhancements:

  1. Try using a UniformGrid instead of a WrapPanel.

  2. Read Josh Smith's article Using RoutedCommands with a ViewModel in WPF and use the techniques described there to create a ReserveRoomCommand property on the RoomViewModel. Set the CommandBinding in the RoomViewModel data template to {Binding ReserveRoomCommand}. Note that once you do this, you'll remove the binding to IsEnabled, because the command binding will enable and disable the button automatically.

  3. If you are going to need to reuse this UI, move the data templates and content presenter into a UserControl.

Robert Rossney
+1 for the amazing contrast of foolish question and serious answer.
egrunin
Henk Holterman