0

次の XAML では、さまざまな DataTemplates を Grid ContentPresenter に直接バインドしようとしています。ContentTemplate がバインドされ、DataTriggers が正しく機能していることを証明するために、Grid 内に Button を配置しました。<Button> を>に置き換えると、<ContentPresenter何も表示されません。明らかに、ここでは本当に単純なものが欠けています。

      <DataTemplate x:Key="MyTemplate">
        <Grid Style="{StaticResource GridAllocatedStyle}">
            <Ellipse Stroke="#FF5A71FB" 
                     StrokeThickness="0.5"
                     Style="{StaticResource EllipseFinanciallyAllocatedStyle}" />
            <TextBlock Style="{StaticResource TextBlockInsideEllipseStyle}" 
                       Text="A"
                       ToolTip="Allocated" />
        </Grid>
    </DataTemplate>


    <DataTemplate x:Key="AllocationTemplate">
        <Grid>           
            <Button> <!-- I want to bind to the Grid.ContentPresenter here -->
                <Button.Style>
                    <Style TargetType="Button">                             
                        <Style.Triggers>                               
                            <DataTrigger Binding="{Binding Allocated}" Value="PreAllocatedBoth">
                                <Setter Property="ContentTemplate" Value="{StaticResource MyTemplate}" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>            
        </Grid>      
    </DataTemplate>

完全を期すために、これは私が達成しようとしているものです:

 <DataTemplate x:Key="AllocationTemplate">
        <Grid>
            <Grid.Style>
                <Style TargetType="Grid">                    
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Allocated}" Value="None">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>                       
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <ContentPresenter> <!-- I want to bind to the Grid.ContentPresenter here -->
                <ContentPresenter.Style>
                    <Style TargetType="ContentPresenter">                             
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Allocated}" Value="FinanciallyAllocated">
                                <Setter Property="ContentTemplate"  Value="{StaticResource MyTemplate}" />
                            </DataTrigger>                                                          
                        </Style.Triggers>
                    </Style>
                </ContentPresenter.Style>
            </ContentPresenter>            
        </Grid>      
    </DataTemplate>
4

1 に答える 1

0

コンテンツが設定されていないため、何も表示されない可能性がありますcontentPresenterか?

ps:問題に関係のないコードがたくさんあるようです(楕円形、多くのテンプレート)。このコードをすべて処理するには時間がかかるので、不要なコードを削除してください。

于 2011-02-23T19:16:19.880 に答える