2

I am trying to make a custom display board to help manage our client rooms.

Table 1 named Rooms [RoomID, RoomNumber, RoomDescription, ADA, RoomStatus]

Table 2 named Beds [BedID, BedNumber, RoomID, BedEnabled]

Table 3 named Clients [ClientID, BedID, RoomID and other fields for client information]

There can be more then 1 bed associated to a room. For example Room 101 has 2 beds, we then can assign 2 clients to room 101.

I been trying to use Grid and StackPanel to list all rooms. Then in each Room List all Beds, then for each bed if a client is assigned I was going to use TextBlock to show client information. I am gathering this is not something I can do straight in the xaml but probably need to do some code behind with loops?

<Window x:Class="BoardDisplay.Window1"        
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:BoardDisplay"
        mc:Ignorable="d"
        Title="Window1" Height="450" Width="800" Loaded="Window_Loaded">
    <Window.Resources>
        <local:Room_ManagerDataSet x:Key="room_ManagerDataSet"/>
        <CollectionViewSource x:Key="roomsViewSource" Source="{Binding Rooms, Source={StaticResource room_ManagerDataSet}}"/>
        <CollectionViewSource x:Key="bedsViewSource" Source="{Binding Beds, Source={StaticResource room_ManagerDataSet}}"/>
    </Window.Resources>
    <Grid Margin="10">
        <ItemsControl ItemsSource="{Binding Source={StaticResource roomsViewSource}}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding RoomNumber}" Margin="0,0,5,5">
                        <Grid>
                            <ItemsControl ItemsSource="{Binding Source={StaticResource bedsViewSource}}">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel/>
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding BedNumber}"/>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Grid>
                    </TextBlock>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</Window>
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
J. Gifford
  • 21
  • 2
  • 1
    With MVVM and proper binding, there shouldn't really be anything you are asking for that can't be done in XAML. – Bradley Uffner May 07 '19 at 14:20
  • Not directly related, but I would consider removing `RoomId` from your `Clients` table. Having it there denormalizes your data, introducing the possibility of inconsistent data. Since `Client` has `BedId`, and each `Bed` has a `RoomId`, you can infer the data without it... – Bradley Uffner May 07 '19 at 14:23
  • ...With `RoomId` on `Client`, you could get in to trouble with Room 1 having Bed1, Room 2 having Bed 2, But have a client assigned to Bed 1, in Room 2, which is invalid. – Bradley Uffner May 07 '19 at 14:24
  • @J. Gifford may you accept my answer – Hamit YILDIRIM May 17 '19 at 07:50

1 Answers1

1

If you make right binding i think twoway is possible in your case then you should use updatesourcetrigger like this

https://stackoverflow.com/a/22253816/914284

Text="{Binding Path=SelectedCollectionDevice.BaudRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}

Also, you can use a wrapper

Hamit YILDIRIM
  • 4,224
  • 1
  • 32
  • 35