0

在我的控件中,我正在设置项目控件的数据上下文,该控件会生成这样的控件。这是数据模板...基本上,如您所见,我正在将 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 数据集(数据库表)。当我选择一个值时,键应该自动设置为数据绑定的对象。你明白我的意思。

我知道有数百种方法。触发器、DependantObject、代码隐藏...推荐什么。

4

0 回答 0