0

セル編集テンプレートのデータグリッド内にテキストボックスがあります。テキストボックスに入力されたテキストを各セルのテキストブロックにバインドしたい。このコードを試しましたが、うまくいきません。

ここに私のxamlがあります:

                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <!--<ComboBox x:Name="monday" Width="50"   IsSynchronizedWithCurrentItem="true"   Loaded="monday_Loaded" SelectionChanged="monday_SelectionChanged"></ComboBox>-->
                            <ComboBox x:Name="monday" Width="30"   ItemsSource="{Binding  Path=Subjects}" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" SelectedItem="{Binding SelectedCollectionItem,Mode=TwoWay}"     Loaded="monday_Loaded" SelectionChanged="monday_SelectionChanged"></ComboBox>
                            <ComboBox x:Name="staff" Width="30"  ItemsSource="{Binding  Path=mondstaff}"  DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" SelectedItem="{Binding SelectedCollectionItem1,Mode=TwoWay}"  Loaded="staff_Loaded" SelectionChanged="staff_SelectionChanged"></ComboBox>
                            <TextBox x:Name="monothers" Visibility="Hidden" Text="{Binding  Path=Subjects}" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" SelectedText ="{Binding SelectedCollectionItem2,Mode=TwoWay}"   Width="30" TextChanged="monothers_TextChanged"></TextBox>
                            <!--<ComboBox x:Name="staff" Width="50" Loaded="staff_Loaded"></ComboBox>-->
                        </StackPanel>
                    </DataTemplate>

これが私のコードです:

public string SelectedCollectionItem
        {
            get { return _SelectedCollectionItem; }
            set
            {
                _SelectedCollectionItem = value;
                RaiseProperty2("SelectedCollectionItem2");
            }
        }

誰かがそれを行う方法を知っているなら、親切に私を助けてください。

4

1 に答える 1

0

コードビハインドでこのコードを見逃したと思います

public void monothers_TextChanged(object sender, TextChangedEventArgs e)
{
   var binding = ((TextBox)sender).).GetBindingExpression(TextBox.TextProperty);
   binding.UpdateSource();
}

詳細

このディスカッションを参照してください

Silverlight で MVVM パターンを使用するために TextBox の TextChanged イベントと Command を接続する方法

また、このブログを参照する必要があります

Silverlight TextBox に、Behavior を持つすべての文字のバインディングを更新させる

于 2013-10-25T05:28:28.713 に答える