0

これに間違った方法でアプローチしているのか、解決策が見えないのか、wpf エンジンの制限に達したのかはよくわかりません。DisplayMemberBindingグリッドが入った UserControl があり、それを呼び出しているコントロールから、コントロール内のグリッド ビューに設定しようとしています。

UserControl: (簡潔にするために省略)

<UserControl x:Class="MyAssembly.UserControls.IncludedItems">
    <Grid>
        <ListView x:Name="lstViewItems" Grid.Row="0" ItemsSource="{Binding AffectedFiles, FallbackValue={x:Null}}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Width="90">
                        <GridViewColumn.HeaderTemplate>
                            <DataTemplate>
                                <DockPanel>
                                    <CheckBox Margin="5,2" IsChecked="{Binding Path=DataContext.AllSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, FallbackValue=false}" />
                                    <TextBlock Text="Include?" />
                                </DockPanel>
                            </DataTemplate>
                        </GridViewColumn.HeaderTemplate>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid Width="90">
                                    <CheckBox HorizontalAlignment="Center" IsChecked="{Binding ShouldInclude}" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn
                        x:Name="gvcDisplayPath"
                        Header="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}, Path=ColumnHeader, FallbackValue=Path}" />
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</UserControl>

そのためgvcDisplayPath、呼び出し元のコントロールから DisplayMemberPath を設定できるようにしたいと考えています。

<Window x:localControls="clr-namespace:MyAssembly.UserControls">
    <Grid>
        ...
        <localControls:IncludedItems DataContext="{Binding FallbackValue={StaticResource vmDesignModel}}" DisplayMemberPath="Catalog" ColumnHeader="Site" />
        ...
    </Grid>
</Window>

依存関係プロパティに基づいて、コントロール、ctr、およびOnInitialisedメソッドの分離コードを設定しようとしましたが、うまくいきませんでした (その時点で dp がその値に設定されていなかったため)。

ありがとう

4

1 に答える 1

0

私の最終的な解決策はPropertyChangedCallback、ユーザー コントロールの DependencyProperty 登録にフックし、そこからバインディングを更新することでした (簡潔にするために省略しています)。

public partial class IncludedItems : UserControl {

    public static readonly DependencyProperty DisplayMemberPathProperty = DependencyProperty.Register("DisplayMemberPath", typeof(string), typeof(TargetedItemView), new UIPropertyMetadata("Item", DisplayMemberPathPropertyChanged));

    private static void DisplayMemberPathPropertyChanged(object sender, DependencyPropertyChangedEventArgs e) {
        IncludedItems view = sender as IncludedItems;
        if (null == view)
            return;

        view.gvcDisplayPath.DisplayMemberBinding = new Binding(view.DisplayMemberPath) { TargetNullValue = String.Empty, FallbackValue = String.Empty };
    }

}
于 2013-08-28T08:57:45.943 に答える