Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从具有联接表的数据库动态创建WPF窗口?_C#_Wpf - Fatal编程技术网

C# 如何从具有联接表的数据库动态创建WPF窗口?

C# 如何从具有联接表的数据库动态创建WPF窗口?,c#,wpf,C#,Wpf,我想做一个定制的展示板来帮助管理我们的客户房间 表1命名为房间[房间ID、房间编号、房间描述、ADA、房间状态] 表2命名的床[床号、床号、房间号、床启用] 表3命名的客户[客户ID、BedID、RoomID和其他客户信息字段] 一个房间可以关联多张床。例如,101房间有两张床,我们可以为101房间分配两位客户 我一直在尝试使用Grid和StackPanel列出所有房间。然后在每个房间列出所有床,然后对于每个床,如果分配了客户,我将使用TextBlock显示客户信息。我想这不是我可以在xaml中

我想做一个定制的展示板来帮助管理我们的客户房间

表1命名为
房间[房间ID、房间编号、房间描述、ADA、房间状态]

表2命名的
床[床号、床号、房间号、床启用]

表3命名的
客户[客户ID、BedID、RoomID和其他客户信息字段]

一个房间可以关联多张床。例如,101房间有两张床,我们可以为101房间分配两位客户

我一直在尝试使用Grid和StackPanel列出所有房间。然后在每个房间列出所有床,然后对于每个床,如果分配了客户,我将使用TextBlock显示客户信息。我想这不是我可以在xaml中直接做的事情,但可能需要用循环来做一些代码隐藏

<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>

如果您进行了正确的绑定,我认为在您的情况下有两种可能,那么您应该像这样使用updatesourcetrigger


此外,您可以使用MVVM的包装器/P>和适当的绑定,在XAML中不应该有任何您不能请求的东西。不是直接相关的,但是我会考虑从<代码>客户端< /C> >表中删除<代码> RoomId <代码>。将其放在那里会使您的数据非规范化,从而引入数据不一致的可能性。由于

Client
BedId
,并且每个
Bed
都有
RoomId
,您可以在没有它的情况下推断数据……如果
RoomId
Client
上,您可能会遇到麻烦,1号房间有床1,2号房间有床2,但在2号房间有一个客户分配到1号床,这是无效的。@J.吉福德,你可以接受我的回答吗
Text="{Binding Path=SelectedCollectionDevice.BaudRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}