0

DataGridTextColumn を別の DataContext にバインドする必要があります。DaatGridComboBox でこれを正しく行っているため、これが可能であることはわかっています。私が現在持っているコードは

       <DataGridTextColumn Header="Name" binding={wont work in here as this element is bounded to the itemsource of the DataGrid} IsReadOnly="True" Width="150">
                <DataGridTextColumn.ElementStyle>
                    <Style TargetType="TextBlock">
                        <Setter Property="Text" 
                        Value="{Binding DataContext.CustomerCollection.Name}"></Setter>
                    </Style>
                </DataGridTextColumn.ElementStyle>         
            </DataGridTextColumn>

私が間違ったことをしましたか?

---- bindingProxy について --

記事にあるように BindingProxy クラスをセットアップしました。そしてこれを持って

       <DataGrid.Resources>
            <l:BindingProxy x:Key="proxy" Data="{Binding}" />
        </DataGrid.Resources>
        
                <DataGridTextColumn.ElementStyle>
                    <Style TargetType="TextBlock">
                        <Setter Property="Text" 
                        Value="{Binding Data.Name, Source={StaticResource proxy}}"></Setter>
                    </Style>
                </DataGridTextColumn.ElementStyle>

しかし、なぜ要素「名前」を知っているのでしょうか?

乾杯

4

1 に答える 1

0

BindingProxyを使用できます。DataContextが継承されていない場合は、データにバインドできます。

于 2014-04-16T12:49:19.683 に答える