Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
930 views
in Technique[技术] by (71.8m points)

wpf - convert XAML to c#

I need to convert the followinf code to c# code. There is a tool to do it automatically? thank you

 <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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I thought doing this shouldn't be that hard (using CodeDOM), so I started working on a solution. The source is available at github. It's really just a beginning, it doesn't support many of the features of XAML, but it works for the code in the question.

If you are serious about this, you can work on that code further.

The XAML in the question produces the following output, that seems to work:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...