1 <WrapPanel Name="w1" Grid.Row="3" DataContext="{Binding RightRoom}"> 2 <StackPanel Orientation="Horizontal" Margin="5"> 3 <TextBlock Text="房间号:"></TextBlock> 4 <TextBox x:Name="txt_houseID" Width="62" IsReadOnly="True" Text="{Binding RoomId,UpdateSourceTrigger=PropertyChanged}"></TextBox> 5 </StackPanel> 6 <StackPanel Orientation="Horizontal" Margin="5" > 7 <TextBlock Text="类型名称:"></TextBlock> 8 <ComboBox Name="cb_type" Width="57" DisplayMemberPath="TypeName" SelectedValuePath="TypeId" 9 ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}},Path=ComboText,Mode=OneWay}"></ComboBox> 10 </StackPanel> 11 <StackPanel Orientation="Horizontal" Margin="5"> 12 <TextBlock Text="价格:"></TextBlock> 13 <TextBox x:Name="txt_Price" Width="50" Text="{Binding Number,UpdateSourceTrigger=PropertyChanged}"></TextBox> 14 </StackPanel> 15 <StackPanel Orientation="Horizontal" Margin="5"> 16 <TextBlock Text="入住人数:"></TextBlock> 17 <TextBox x:Name="txt_num" Width="67" Text="{Binding GuestNumber,UpdateSourceTrigger=PropertyChanged}"></TextBox> 18 </StackPanel> 19 <StackPanel Orientation="Horizontal" Margin="5"> 20 <TextBlock Text="床位数:"></TextBlock> 21 <TextBox x:Name="txt_bedNum" Width="65" Text="{Binding BedNumber,UpdateSourceTrigger=PropertyChanged}"></TextBox> 22 </StackPanel> 23 <StackPanel Orientation="Horizontal" Margin="5"> 24 <TextBlock Text="状态:"></TextBlock> 25 <ComboBox Name="cb_statue" Width="57" Text="{Binding State,UpdateSourceTrigger=PropertyChanged}"> 26 <ComboBoxItem Content="空闲"></ComboBoxItem> 27 <ComboBoxItem Content="入住"></ComboBoxItem> 28 <ComboBoxItem Content="维修"></ComboBoxItem> 29 </ComboBox> 30 </StackPanel> 31 <StackPanel Orientation="Horizontal" Margin="5"> 32 <TextBlock Text="备注:"></TextBlock> 33 <TextBox x:Name="Description" Width="637" TextWrapping="Wrap" Height="50" Text="{Binding Description,UpdateSourceTrigger=PropertyChanged}"></TextBox> 34 </StackPanel> 35 </WrapPanel>
问题出在combobox上,因为在WrapPanel中绑定了datacontent而我又要绑定combobox,所以将combobox的源地址指向Window可是还是找不到数据呢?
试试
ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Window}},Path=DataContext.ComboText,Mode=OneWay}">