我如何以编程方式在Wpf中创建此模板 [英] How Could I Create This Template Programmically In Wpf

查看:121
本文介绍了我如何以编程方式在Wpf中创建此模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



How could i Create this template programmically in wpf?

<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>

推荐答案

如果您的基于XAML的示例应用程序已经在运行,那么这一切都已经以编程方式完成。你只需要看到它。您在XAML中完成的所有操作都会在构建期间转换为一些自动生成的C#代码。找到那些文件;它们被放在项目文件目录的obj子目录下。



顺便说一句,这是一个简单的非常通用的方法,用于找到如何做所有事情你可以使用XAML和/或设计师。此配方也适用于表格。



-SA
If your sample application based on your XAML is already working, it all is already done "programmatically". You only need to see it. Everything you have done in XAML is translated to some auto-generated C# code during the build. Find those files; they are put under the "obj" sub-directory of your project file's directory.

By the way, this is a simple very universal recipe for finding how to do everything you can do with XAML and/or the designer. This recipe works for Forms as well.

—SA


这篇关于我如何以编程方式在Wpf中创建此模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆