create datatemplate code behind

前端 未结 3 490
一向
一向 2021-01-14 05:57

I am trying to create a ListBox view for show data, and I want it to contain a ListBox with a datatemplate for 2 columns \"Product ID & Product Barcode\"

I want

3条回答
  •  爱一瞬间的悲伤
    2021-01-14 06:42

    I have created DataTemplate like this:

    private DataTemplate getDataTemplate()
    {
        DataTemplate retVal = null;
        String markup = String.Empty;
    
        markup = "";
        markup += "";
        markup += "";
        markup += "";
        markup += "";
    
        retVal = (DataTemplate)XamlReader.Load(markup);
    
        return retVal;
    }
    

    ...and then call this method where you need it (like OnApplyTemplate)

    this.ContentTemplate = getDataTemplate();
    

    NOTE : You may have to change the "xmlns" for WPF, because this example is taken from one of my Silverlight projects. But the idea is the same.

提交回复
热议问题