加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

将XAML转换为c#

发布时间:2020-12-16 01:46:15 所属栏目:百科 来源:网络整理
导读:我需要将followinf代码转换为c#代码. 有一个工具可以自动完成吗? 谢谢 ListView Name="listView" Margin="0,164" ListView.View GridView GridView.Columns GridViewColumn Header="Devise" DisplayMemberBinding="{Binding Path=devise}" Width="80" / Gri
我需要将followinf代码转换为c#代码.
有一个工具可以自动完成吗?
谢谢

<ListView Name="listView" Margin="0,164">
        <ListView.View>
            <GridView>
                <GridView.Columns>
                    <GridViewColumn Header="Devise" DisplayMemberBinding="{Binding Path=devise}" Width="80" />
                    <GridViewColumn Header="Libelle" DisplayMemberBinding="{Binding Path=label}" Width="120" />
                    <GridViewColumn Header="Unite" DisplayMemberBinding="{Binding Path=unite}" Width="80" />
                    <GridViewColumn Header="Achat" DisplayMemberBinding="{Binding Path=achatBanque}" Width="80" />
                    <GridViewColumn Header="Vente" DisplayMemberBinding="{Binding Path=venteBanque}" Width="80" />    
                </GridView.Columns>
            </GridView>
        </ListView.View>
    </ListView>

解决方法

我认为这样做不应该那么难(使用CodeDOM),所以我开始研究解决方案.源代码可用 at github.它只是一个开始,它不支持XAML的许多功能,但它适用于问题中的代码.

如果您对此很认真,可以进一步处理该代码.

问题中的XAML产生以下输出,似乎有效:

private ListView Get()
{
    ListView listView = new ListView();
    listView.Name = "listView";
    listView.Margin = ((Thickness)(TypeDescriptor.GetConverter(typeof(Thickness)).ConvertFromInvariantString("0,164")));
    GridView gridView = new GridView();
    GridViewColumn gridViewColumn = new GridViewColumn();
    gridViewColumn.Header = "Devise";
    Binding binding = new Binding();
    binding.Path = ((PropertyPath)(TypeDescriptor.GetConverter(typeof(PropertyPath)).ConvertFromInvariantString("devise")));
    gridViewColumn.DisplayMemberBinding = binding;
    gridViewColumn.Width = 80D;
    gridView.Columns.Add(gridViewColumn);
    GridViewColumn gridViewColumn2 = new GridViewColumn();
    gridViewColumn2.Header = "Libelle";
    Binding binding2 = new Binding();
    binding2.Path = ((PropertyPath)(TypeDescriptor.GetConverter(typeof(PropertyPath)).ConvertFromInvariantString("label")));
    gridViewColumn2.DisplayMemberBinding = binding2;
    gridViewColumn2.Width = 120D;
    gridView.Columns.Add(gridViewColumn2);
    GridViewColumn gridViewColumn3 = new GridViewColumn();
    gridViewColumn3.Header = "Unite";
    Binding binding3 = new Binding();
    binding3.Path = ((PropertyPath)(TypeDescriptor.GetConverter(typeof(PropertyPath)).ConvertFromInvariantString("unite")));
    gridViewColumn3.DisplayMemberBinding = binding3;
    gridViewColumn3.Width = 80D;
    gridView.Columns.Add(gridViewColumn3);
    GridViewColumn gridViewColumn4 = new GridViewColumn();
    gridViewColumn4.Header = "Achat";
    Binding binding4 = new Binding();
    binding4.Path = ((PropertyPath)(TypeDescriptor.GetConverter(typeof(PropertyPath)).ConvertFromInvariantString("achatBanque")));
    gridViewColumn4.DisplayMemberBinding = binding4;
    gridViewColumn4.Width = 80D;
    gridView.Columns.Add(gridViewColumn4);
    GridViewColumn gridViewColumn5 = new GridViewColumn();
    gridViewColumn5.Header = "Vente";
    Binding binding5 = new Binding();
    binding5.Path = ((PropertyPath)(TypeDescriptor.GetConverter(typeof(PropertyPath)).ConvertFromInvariantString("venteBanque")));
    gridViewColumn5.DisplayMemberBinding = binding5;
    gridViewColumn5.Width = 80D;
    gridView.Columns.Add(gridViewColumn5);
    listView.View = gridView;
    return listView;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读