Create ListView ItemTemplate programmatically/dynamically

Hi,
here is my problem:
I have a ListView control on my xaml page. But the data item structure is different from on item to another. Sometimes i need a Grid with 4 columns, sometimes with 5, sometimes with 6. So my idea was to dynamically create the data template and change the
ColumnDefinitions programmatically . But i don´t find a way to do it. I come from the HTML/JS Windows App Devolpment side, and there it is relatively easy to do such things ...

try this:
<Grid>
<ListView x:Name="listview">
<ListView.ItemContainerStyle >
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate >
<DataTemplate >
<StackPanel >
<TextBlock Text="{Binding GroupName}"/>
<ListView ItemsSource="{Binding Items}" Background="Blue" >
<ListView.ItemsPanel >
<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" MaximumRowsOrColumns="1"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate >
<DataTemplate >
<Border BorderBrush="Yellow" BorderThickness="2" Width="24" >
<TextBlock Text="{Binding Data}" FontSize="18" Foreground="White" />
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
namespace App1
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
public MainPage()
this.InitializeComponent();
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
var d =BuildTestData();
listview.ItemsSource = d;
foreach (var item in d)
Debug.WriteLine(item.GroupName);
private List<MyGroup> BuildTestData()
List<MyGroup> groups = new List<MyGroup>();
List<Detail> c1 = new List<Detail>();
c1.Add(new Detail() { Data = "1" });
c1.Add(new Detail() { Data = "2" });
c1.Add(new Detail() { Data = "3" });
groups.Add(new MyGroup() { Items = c1, GroupName = "First" });
List<Detail> c2 = new List<Detail>();
c2.Add(new Detail() { Data = "11" });
c2.Add(new Detail() { Data = "21" });
c2.Add(new Detail() { Data = "31" });
c2.Add(new Detail() { Data = "41" });
groups.Add(new MyGroup() { Items = c2, GroupName = "Second" });
List<Detail> c3 = new List<Detail>();
c3.Add(new Detail() { Data = "A" });
c3.Add(new Detail() { Data = "B" });
c3.Add(new Detail() { Data = "C" });
c3.Add(new Detail() { Data = "D" });
c3.Add(new Detail() { Data = "E" });
groups.Add(new MyGroup() { Items = c3, GroupName = "Third" });
return groups;
public class MyGroup
public List<Detail> Items
{ get; set; }
public string GroupName
get;
set;
public class Detail
public string Data
get;
set;
在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

Similar Messages

  • Create Check Box Programmatically

    Hi ALL
    Let me know how to Create Check Box Programmatically using table column.
    Thanking You
    Rehards
    Lakmal

    You can't create Forms widgets dynamically. What you have to do is create them at design time and then hide/unhide them at runtime using things like stacked canvases.
    Regards
    Grant Ronald

  • How to create the selection screen dynamically

    Hi,
    I have a requirement to create the selection screen Dynamically. All the fields that should appear on the selection screen will be available in a custom table. So, based on the entries available in the Z tables, the selection screen should be built. Eg. If there are 10 records available in the Z table, the selection screen should consist of 10 fields. If there are 100 entries, the Selection screen should contain 100 fields. and the logic to build this selection screen should be carried out dynamically in the program.
    Could anyone of you please share the valuable inputs on this. If anyone has the sample code to do this, please share.
    Thanks in advance.
    Regards,
    Paddu.

    Hi,
    Kindly go through this sample program below:
    DEMO_LIST_FORMAT_INPUT *and
    check this function module:
    FREE_SELECTIONS_DIALOG *.
    Hope it helps
    Regards
    Mansi

  • How to Create a Table Component Dynamically based on the Need

    Hello all,
    I have a problem i need to create dynamically tables based on the no of records in the database. How can i create the table object using java code.
    Please help.

    Winston's blog will probably be helpful:
    How to create a table component dynamically:
    http://blogs.sun.com/roller/page/winston?entry=creating_dynamic_table
    Adding components to a dynamically created table
    http://blogs.sun.com/roller/page/winston?entry=dynamic_button_table
    Lark
    Creator Team

  • How to create a webdynpro view dynamically and embed into view container?

    Hi all,
    Anyone knows how to create a view dynamically and embed the view into an existing view container?
    My layout looks like this:
    I have an existing view named main_view.
    Inside main_view, I create a view ui container named vcu_view.
    I embed the main_view into my window.
    I need the codes to create a view dynamically and embed the view into the view container. Anyone have any idea?
    Thanks in advance.
    Rgds,
    Siong Chao

    hi Siong Chao   ,,
    empty view insence ..( create a view without any UI element in it  ) in design time ..
    >
    Siong Chao wrote:
    > Hi Chinnaiya,
    >
    > How do you create an empty view dynamically then? Thanks in advance.
    i think we cannot create a new view dynamically because it is a webdynpro restriction ..
    NOTE: experts correct me if i am wrong in this answer
    Regards
    Chinnaiya P

  • Problem creating an internal table dynamically

    Hi,
    I'm trying to create an internal table dynamically as i would be able to determine the structure of the table based on the user input.
    I've used the sample code from this forum ...
    REPORT  ZRICH_0003       .
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: alv_fldcat type slis_t_fieldcat_alv,
                   it_fldcat type lvc_t_fcat.
                   type-pools : abap.
    data : it_details type abap_compdescr_tab,
           wa_details type abap_compdescr.
    data : ref_descr type ref to cl_abap_structdescr.
    data: new_table type ref to data,
          new_line  type ref to data,
          wa_it_fldcat type lvc_s_fcat.
          selection-screen begin of block b1 with frame title text.
    parameters: p_table(30) type c.
    selection-screen end of block b1.
    Get the structure of the table.
    ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
    it_details[] = ref_descr->components[].
    loop at it_details into wa_details.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = wa_details-name .
      wa_it_fldcat-datatype = wa_details-type_kind.
      wa_it_fldcat-inttype = wa_details-type_kind.
      wa_it_fldcat-intlen = wa_details-length.
      wa_it_fldcat-decimals = wa_details-decimals.
      append wa_it_fldcat to it_fldcat .
      endloop.
    Create dynamic internal table and assign to FS
    call method cl_alv_table_create=>create_dynamic_table
                exporting
                it_fieldcatalog = it_fldcat
                importing
                ep_table        = new_table.
    assign new_table->* to <dyn_table>.
    Create dynamic work area and assign to FS
    create data new_line like line of <dyn_table>.
    assign new_line->* to <dyn_wa>.
    <b>* Select Data from table.
    select * into table <dyn_table>           from
    (p_table).</b>
    Write out data from table.
    loop at <dyn_table> into <dyn_wa>.
    do.
    assign component  sy-index  of structure <dyn_wa> to <dyn_field>.
    if sy-subrc <> 0.
    exit.
    endif.
    if sy-index = 1.
    write:/ <dyn_field>.
    else.
    write: <dyn_field>.
    endif.
    enddo.
    endloop.
    I'm able to get the structure of the table that i want, but when i'm trying to select data from the table into this internal table..as highlighted in the sample code above..i'm getting a short dump...saying that ' the database table is 600 bytes wide but the internal table is only 576 bytes wide.
    The internal table is declared as
    field-symbols: <dyn_table> type standard table..
    Could anyone please tell me how to rectify this.
    Thanks in advance,
    Harsha.

    Hi Smitha,
    I'm building the internal table by getting the structure using the method
    cl_abap_typedescr=>describe_by_name( p_table ).
    where p_table is the table name determined dynamically..
    Now using this structure, i'm building an internal table by calling the method
    call method cl_alv_table_create=>create_dynamic_table
    I've checked all the fields after the internal table has been created .. and it contains all the fields of the table that i'm supplying initially..
    But when i read data into that internal table, it gives me that dump..I've described it in this post earlier.
    Any more suggestions would be very helpful.
    Thanks,
    Harsha

  • Can I create a custom-scripted dynamic stamp in Acrobat Standard or do I have to buy Acrobat Pro?

    I am researching options for the company I work for to take it's invoicing system paperless and I need to know if I can create a custom-scripted dynamic stamp in Acrobat Standard or is that possible only in Acrobat Pro?

    You can create a custom dynamic stamp in Std. and Pro. and you can use the dynamic stamp in Reader as well. Here is an infographic on Creating a Custom Dynamic Stamp in Acrobat XI.

  • How to create an UI element dynamically on action in drop down?

    Hi,
    How to create an UI element dynamically on action of selecting a value from the  drop down?
    help out with the steps i need to follow..

    Hi,
    <u><i><b>Dynamic UI Element creation</b></i></u>
    We can create it only in the WD Modify View.
    Get the instance for the Root UI Element Container.
    Create the UI element Ex: Input Field, Text View etc.
    Bind the UI Element to the Attribute Value.
    Now bind the UI Element to the Root UI Element Container.
              IWDTransparentContainer root =(IWDTransparentContainer)view.getRootElement();
              IWDDropdownByIndex DdbName = (IWDDropdownByIndex)view.createElement(IWDDropdownByIndex.class,"DdbName");
              IWDDropdownByIndex DdbAge = (IWDDropdownByIndex)view.createElement(IWDDropdownByIndex.class,"DdbAge");
              IWDDropdownByIndex DdbGender = (IWDDropdownByIndex)view.createElement(IWDDropdownByIndex.class,"DdbGender");
              IWDNode Mad =wdContext.getChildNode("Person",0);
              IWDAttributeInfo NameAtt = Mad.getNodeInfo().getAttribute("Name");
              IWDAttributeInfo AgeAtt = Mad.getNodeInfo().getAttribute("Age");
              IWDAttributeInfo GenderAtt = Mad.getNodeInfo().getAttribute("Gender");
              DdbName.bindValue(NameAtt);
              DdbAge.bindValue(AgeAtt);
              DdbGender.bindValue(GenderAtt);
              root.addChild(DdbName);     
              root.addChild(DdbAge);
              root.addChild(DdbGender);
    <u><i><b>Dynamic Action Creation</b></i></u>
    Create the Action in the Action tab.
    Create a Button.
    Get the reference for the created action (Through the Event Handler).
    Bind the Action to the Button.
    Bind the Button to the Root UI element Container.
    IWDButton ButGo = (IWDButton)view.createElement(IWDButton.class,"ButGo");
    IWDAction ActGo = wdThis.wdCreateAction(IPrivateStartView.WDActionEventHandler.GO,"Click");
    ButGo.setOnAction(ActGo);
    root.addChild(ButGo);
    Now write the required code for the Event Handler that is associated with the Action.
    //@@begin onActionGo(ServerEvent)
        IWDNode Mad = wdContext.getChildNode("Person",0);
         wdComponentAPI.getMessageManager().reportSuccess(Mad.getCurrentElement().getAttributeAsText("Name"));
         wdComponentAPI.getMessageManager().reportSuccess(Mad.getCurrentElement().getAttributeAsText("Age"));
         wdComponentAPI.getMessageManager().reportSuccess(Mad.getCurrentElement().getAttributeAsText("Gender"));
    //@@end
    Regards
    SURYA

  • I create a CNiGraph control dynamically, But why havent I seen the Demo Mode Message Window?

    I am a licenced user of Mesurement Studio. I create a CNiGraph control dynamically. All work well.
    Then I copied my source code to another PC, I run "regsvr32 cwui.ocx", I found I can compile my source code on that computer, without any message box.
    But some people said that there will be a Demo Mode Message box.
    That's to say, any one can copy my source code to other computer and compile it well, then how can I protect my right?
    On what condition the Demo Mode Message Box will appear? I want it to show up when others use my code.

    It sounds like you were expecting the message box to come up at compile-time. Is that correct? If so, that is not expected and should not ever happen - the message box that you're referring to should not come up until you actually run the application. However, if you're dynamically creating the control and you are specifying the license string at creation time in your code, I expect it would still work when you take the code to another machine. Could you please reply with more information about what you're trying to do and how you expect this to work? Thanks.
    - Elton

  • Creating JAR files programmatically

    I am trying to create JAR files programmatically using the java.util.zip and java.util.jar APIs. I am starting with just a set of directories containing .class files. I can seem to make the JAR but if I try to use any of the classes in it they don't work. But, if I unzip the JAR using WinZip, the classes are usable. So I am somehow building the JAR file incorrectly. Does anyone have any ideas or suggestions? The code is pretty long so I won't post it yet but I can send it to you if you'd like to see it. Contact by email if you'd like to see the code. Thanks.

    What paths are you encoding? Here are a couple of rules:
    1 - All paths are '/' separated, and do not begin with a '/'.
    2 - All paths are relative (see 1) and contain the exact package name of the class, plus the class.
    E.G., the class java.lang.Object would look like this in your jar:
    java/lang/Object.classNothing more or less.

  • Create ADF elements programmatically using Java

    Hello,
    I use JDeveloper 11.1.1.2.0 and Java 6 (of course)
    <f:view>
    <af:document title="Some Text" id="d1">
    <af:messages id="m1"/>
    <af:form id="f1">
    <af:panelGroupLayout layout="vertical" id="pgl1" halign="center">
    <af:outputText value="Song" id="ot1"/>
    <af:media source="/midi/song.midi"
    standbyText="Song sample" player="quicktime" id="m2"
    contentType="audio/x-midi"/>
    </af:panelGroupLayout>
    </af:form>
    </af:document>
    </f:view>
    I would like to create this construct programmatically. The reason is that I would like to create not only one <af:media> tag but more. But for some reasons it's not a fixed portion of songs I could anticipate. Therefore I want to take the construct above as a template and add more <af:media> tags I need at the moment I realize how many songs I want to play.
    I would like to call this construct from a command button or link on another side to open a new window in which the user could choose among different songs to play.
    Do I have to use DOM or XPath to setup this or is ADF able to offer some support ?
    Best regards
    Martin
    Edited by: user463656 on 05.05.2010 01:41

    Should be something like:
    <f:view>
    <af:document title="Some Text" id="d1">
    <af:messages id="m1"/>
    <af:form id="f1">
    <af:panelGroupLayout layout="vertical" id="pgl1" halign="center"  binding="#{ManagedBean.panelGroup}">
    <af:outputText value="Song" id="ot1"/>
    </af:panelGroupLayout>
    </af:form>
    </af:document>
    </f:view>And somewhere in the MagaedBean methods:
    public class ManagedBean{
    RichMedia rm;
    while .. {
    rm = new RichMedia();
    rm.setstandbyText(....);
    rm.setSource(....);
    panelGroup.getChildren().add(rm);
    }And then refresh the panelgroup with partialTrigger ot partialTarget.
    Edited by: Valhery on 2010-5-5 2:04

  • How to create an IDoc programmatically at Inbound side?

    Hi,
    How to create an IDoc programmatically at Inbound side?
    Assume that you have a file(material master details) which is enough to create master data.
    Regards,
    Thiyagu

    Read the documentation of this FM first:
    FU IDOC_INBOUND_ASYNCHRONOUS                                                                               
    K. tekst
                                                                                    IDoc inbound processing via tRFC                                                                               
    Functionality
                                                                                    This function module starts inbound processing in the case of port type    
        "tRFC". The function module is a successor to INBOUND_IDOC_PROCESS,        
        which processes IDocs in the Release 4.0 record types. If you are          
        processing IDocs in Release 3.X record types, the function module          
        INBOUND_IDOC_PROCESS must still be called.                                                                               
    The function module checks the ID 'EDI_MES' in authorization object        
        B_ALE_RECV against the received message type.                                                                               
    The IDocs are saved by the function module IDOC_INBOUND_WRITE_TO_DB (a     
        COMMIT for all IDocs) and then transferred directly to the application     
        by the dispatcher module IDOC_START_INBOUND.                                                                               
    Parameter
                                                                                    IDOC_CONTROL_REC_40                                                        
        IDOC_DATA_REC_40                                                                               
    Exceptions
                                                                                    Functiegroep                                                                               
    Edited by: Micky Oestreich on Jun 11, 2009 12:52 PM

  • Create graph based on dynamic table data

    Hi experts ;
    i have JDeve Version 11.1.2.2.0 , i'm create dynamic table based on dynamic SQL query this query return by function in database by based on passing parameter .
    My question :-
    1- How create graph based on dynamic table and contral it at run time ?
    Thanks & Best Regards

    Hi Mostafa,
    You can retrieve the data from your sql query in a backing bean and pass it on to Graph using the setTabularData method.
    Here is the javadoc for the setTabulardata method:
    http://docs.oracle.com/cd/E16162_01/apirefs.1112/e17492/oracle/dss/dataView/CommonDataview.html#setTabularData%28java.util.List%29
    Hope this helps
    Katia

  • How to create a field catalogue dynamically?

    Hi guys,
          I have to create a field catalogue dynamically. I am creating the internal table dynamcially. It is <fs_dyn_table>. I am passing this to the function module REUSE_ALV_FIELDCATALOG_MERGE.
    <fs_dyn_table> contains five fields kunnr, land1, name1, ort01 and telf1 which i am passing from selection screen.
    This is how my function module is
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
         i_program_name               = sy-repid
       i_internal_tabname             = '<FS_DYN_TABLE>'
       i_inclname                     = sy-repid
        CHANGING
          ct_fieldcat                  = it_fcat
       EXCEPTIONS
         inconsistent_interface       = 1
         program_error                = 2
         OTHERS                       = 3.
    I am not getting any values in the internal table it_fcat.
    I would like to know if there is any other way to create field catalogue?
    Help will be appreciated.
    Thanks,
    Ibrahim

    Hi,
    Kindly refer wiki links:
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/complete%252bcode%252bfor%252bdynamic%252bfield%252bcatalog%252bcreation
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/create%252ban%252balv%252b(%252bUsing%252bOOABAP%252b)with%252bdynamic%252bField-Catalog
    Hope they help you.
    Regards,
    Tarun

  • Creating context node with dynamic type

    When we are creating context node thru wizard,  Dictionary type must be filled. I'm trying to create Context node manually.Did any one tried created Context node class with Dynamic type.

    Hi Prasad,
    I have a similar requirement.
    Can you please share with me how did you create context node with dynamic table data?
    Thanks
    Vicky

Maybe you are looking for

  • Missing photos after importing from iPhoto

    I have a big iPhoto library that span from 2002 until today. Launching Photo for the first time started the import of the default iPhoto library, when finished the problem is not everything has been imported. I have not done photo by photo check, but

  • Error when mantaining a dimension

    I have a very simple AW with 3 dimensions (PLAYER, YEAR, TEAM) containing baseball data. The TEAM dimension has one hierarchy with 3 levels: TEAMS_ALL, LEAGUE, TEAMID. For a spell, I was able to maintain this dimension successfully and use it in repo

  • Integration between Manager Self-Service Role (ESS in MSS) and Custom BSP

    Hi guys, Hello, we want to integrate a BSP page through ESS We have created a link like change personal data for an employee (it's working). How can I catch current Person Number selected by the employee from the team viewer for this specific BSP? We

  • Videoclips from pocketcamera crashes quicktime..?

    I am haveing a problem using videoclips in iphoto 08 / Imovie 08... It is probably a Quicktime problem I am told - here is my question I asked in the Iphoto-discussion..: The videoclips are importet with no problem along with the photos as expected.

  • How do I get keyboard to appear when adding a contact?

    My keyboard doesn't appear when I try to add a contact.  Can anyone help?