gpt4 book ai didi

c# - 将 XAML 转换为 C#

转载 作者:太空狗 更新时间:2023-10-30 00:34:43 25 4
gpt4 key购买 nike

我需要将以下代码转换为 C# 代码。有没有工具可以自动完成?谢谢

 <ListView Name="listView" Margin="0,0,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,0,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;
}

关于c# - 将 XAML 转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6930754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com