我怎么能在wpf中以编程方式创建此模板?

时间:2014-08-05 06:27:35

标签: c# xaml

我如何在wpf中以编程方式创建此模板?

我在保证金定义中存在问题

如何在运行时和C#代码中添加RelativeSource,AncestorType和Binding?

抱歉我的英文

<DataTemplate x:Key="CellTemplate_Name">
      <DockPanel>
        <ToggleButton x:Name="Expander" 
                      Style="{StaticResource ExpandCollapseToggleStyle}" 
                      Margin="{Binding Level,
                             Converter={StaticResource 
                                        LevelToIndentConverter},
                             RelativeSource={RelativeSource 
                                             AncestorType=
                                             {x:Type l:TreeListViewItem}}}"
                      IsChecked="{Binding Path=IsExpanded,
                                 RelativeSource={RelativeSource 
                                                 AncestorType=
                                                  {x:Type l:TreeListViewItem}}}"
                      ClickMode="Press"/>
        <TextBlock Text="{Binding Name}"/>
      </DockPanel>
      <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding Path=HasItems,
                               RelativeSource={RelativeSource 
                               AncestorType={x:Type l:TreeListViewItem}}}" 
                     Value="False">
          <Setter TargetName="Expander"
                  Property="Visibility"
                  Value="Hidden"/>
        </DataTrigger>
      </DataTemplate.Triggers>
    </DataTemplate>

0 个答案:

没有答案