0

観察/問題/問題があります。

私のアプリでは、「ItemsControl」に「DataContext」として設定しているEFオブジェクトのリスト(「Car」と呼びましょう)をロードしました。ItemsControl には、テキスト ボックスなどのオブジェクト (「車」) のプロパティを表す一連のコントロールがあります。

私が理解している限り、プロパティをコントロールに割り当てるとバインドする必要があり、TextBox の値を変更する場合はオブジェクトでも変更する必要があります。しかし、これは私のアプリでは起こっていません。何か不足していますか?

私が知る限り、逆に、変更が Object->GUI から発生した場合、プロパティのクラスは Interface "INotifyPropertyChanged" を実装する必要がありますが、GUI-Object からの変更がある場合は、このようなことを行う必要はありません。 .

私は何かを見逃しているのでしょうか、誤解されているのでしょうか、それとも単にバグのあるコードを書いているのでしょうか?

編集済み- 1回目- 提案のためのthnx

<ItemsControl Name="icRoles" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding}" >
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <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="40" />
                    <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="Uloga" Grid.ColumnSpan="2" Height="28" HorizontalAlignment="Center" Name="label8" VerticalAlignment="Center" />

                <Label Content="ID:" Grid.Row="1" Height="28" Name="label1" VerticalAlignment="Top" />
                <Label Content="Ime Uloge:" Grid.Row="2" Height="28" Name="label2" VerticalAlignment="Top" />
                <Label Content="Prikazano ime:" Grid.Row="3" Height="28" Name="label3" VerticalAlignment="Top" />
                <Label Content="Tip Uloge:" Grid.Row="4" Height="28" Name="label4" VerticalAlignment="Top" />
                <Label Content="Datum Stvaranja:" Grid.Row="5" Height="28" Name="label5" VerticalAlignment="Top" />
                <Label Content="Datum promjene:" Grid.Row="6" Height="28" Name="label6" VerticalAlignment="Top" />
                <Label Content="Stanje:" Grid.Row="7" Height="28" Name="label7" VerticalAlignment="Top" />

                <TextBox    Grid.Column="1" Grid.Row="1" Height="23" Text="{Binding ID}" IsEnabled="False" />
                <TextBox    Grid.Column="1" Grid.Row="2" Height="23" Text="{Binding Name}" />
                <TextBox    Grid.Column="1" Grid.Row="3" Height="23" Text="{Binding Text}"  />
                <WrapPanel  Grid.Column="1" Grid.Row="4" Height="25"  />
                <DatePicker Grid.Column="1" Grid.Row="5" Height="25" SelectedDate="{Binding DateCreated}" IsEnabled="False" />
                <DatePicker Grid.Column="1" Grid.Row="6" Height="25" SelectedDate="{Binding DateModified}" IsEnabled="False"  />
                <CheckBox   Grid.Column="1" Grid.Row="7" Height="16" IsChecked="{Binding active}" />
            </Grid>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

編集 - 2回目 は、バインドのモードをコントロールに設定しました。しかし、1つの奇妙なことが起こっています。2 つのテキストボックスのバインディングを

Text="{Binding Path=Name, Mode=TwoWay}"
Text="{Binding Path=Text, Mode=TwoWay}"

ただし、プロパティに設定されているのは最初のものだけです。拳はヌルのまま。

4

1 に答える 1

0

わかった。助けてくれたユーザーからの提案から解決しました

バインディングモードがありませんでした。(Text="{Binding Path=Name, Mode=TwoWay}")

2 つ目の問題は、コントロールがまだフォーカスを持っていたために、コントロールがデータをオブジェクトに保存しなかったことにあります。保存はオブジェクトにコミットされませんでした

于 2013-06-05T15:17:01.750 に答える