在我的控制中,我设置了一个item控件的datacontext,它生成一个这样的控件。这是数据模板...... 基本上,正如您所看到的,我将en EF实体的单个值绑定到控件。
<Grid Name="grdRoles" Background="Gray" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1.4*"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--Subject-->
<Label Content="Podmodul" Grid.ColumnSpan="2" Height="28" HorizontalAlignment="Center" Name="label0" VerticalAlignment="Center" />
<Label Content="ID:" Grid.Row="1" Height="28" Name="label1" VerticalAlignment="Top" />
<Label Content="Ime:" Grid.Row="2" Height="28" Name="label2" VerticalAlignment="Top" />
<Label Content="Opis:" Grid.Row="3" Height="28" Name="label3" VerticalAlignment="Top" />
<!--Expander-->
<Label Content="Modul:" Grid.Row="5" Height="28" Name="label5" VerticalAlignment="Top" />
<Label Content="Dopuštenja:" Grid.Row="6" Height="28" Name="label10" VerticalAlignment="Top" />
<Label Content="Stanje:" Grid.Row="7" Height="28" Name="label11" VerticalAlignment="Top" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" Text="{Binding Path=ID, Mode=OneWay}" IsEnabled="False" />
<TextBox Grid.Column="1" Grid.Row="2" Height="23" Text="{Binding Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="1" Grid.Row="3" Height="23" Text="{Binding Path=Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Expander Grid.Column="0" Grid.Row="4" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" Margin="50, 5, 5, 5" Background="DarkGray">
<Expander.Header>
<Label Content="Definicija:" Grid.Row="6" Height="28" Name="label9" VerticalAlignment="Top" />
</Expander.Header>
<Expander.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="1.4*"/>
</Grid.ColumnDefinitions>
<Label Content="ClassName:" Grid.Row="0" Height="28" Name="label6" VerticalAlignment="Top" />
<Label Content="AssemblyName:" Grid.Row="1" Height="28" Name="label7" VerticalAlignment="Top" />
<Label Content="NameSpace:" Grid.Row="2" Height="28" Name="label8" VerticalAlignment="Top" />
<Label Content="Primaran:" Grid.Row="3" Height="28" Name="label4" VerticalAlignment="Top" />
<TextBox Grid.Column="1" Grid.Row="0" Height="23" Text="{Binding Path=ClassName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="1" Grid.Row="1" Height="23" Text="{Binding Path=AssemblyName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Column="1" Grid.Row="2" Height="23" Text="{Binding Path=NameSpace, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<CheckBox Grid.Column="1" Grid.Row="3" Height="16" IsChecked="{Binding Path=IsPrimary, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</Expander.Content>
</Expander>
<ComboBox Grid.Column="1" Grid.Row="5" Height="25" />
<WrapPanel Grid.Column="1" Grid.Row="6" Height="25" />
<CheckBox Grid.Column="1" Grid.Row="7" Height="16" IsChecked="{Binding Path=active, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</DataTemplate>
我的问题如下......
我也有(在网格的最后),这一个组合框。我想把它绑定到另一个EF数据集(DB表)。当我选择一个值时,该键应自动设置为数据绑定对象。你明白我的意思了。
我知道有数百种方法。触发器,DependantObject,代码隐藏... 建议什么。