Click here to Skip to main content
15,893,486 members
Home / Discussions / WPF
   

WPF

 
QuestionTwo questions about the TreeView control Pin
Mc_Topaz16-May-14 1:45
Mc_Topaz16-May-14 1:45 
AnswerRe: Two questions about the TreeView control Pin
SledgeHammer0116-May-14 6:45
SledgeHammer0116-May-14 6:45 
QuestionRe: Two questions about the TreeView control Pin
Mc_Topaz16-May-14 7:40
Mc_Topaz16-May-14 7:40 
AnswerRe: Two questions about the TreeView control Pin
SledgeHammer0116-May-14 8:16
SledgeHammer0116-May-14 8:16 
GeneralRe: Two questions about the TreeView control Pin
Mc_Topaz16-May-14 9:08
Mc_Topaz16-May-14 9:08 
QuestionOCR using Microsoft Office Document Imaging 12.0 Type Library in WPF application Pin
Member 785476914-May-14 20:20
Member 785476914-May-14 20:20 
AnswerRe: OCR using Microsoft Office Document Imaging 12.0 Type Library in WPF application Pin
AlphaDeltaTheta15-May-14 16:48
AlphaDeltaTheta15-May-14 16:48 
QuestionSilverlight: Exception with ListBox and nested collection Pin
tongo7612-May-14 23:01
tongo7612-May-14 23:01 
Hi
Any help would be very appreciated.

i have a listbox defined in the MainPage.xaml which a bind to a collection of nested objects (boxes).

XML
<ListBox x:Name="MyListBox"
                 ItemTemplate="{StaticResource NestedDataTemplate}"/>


The box:
C#
public class Box
{
  public string BoxName { get; set; }
  public ObservableCollection<Box> Boxes { get; set; }
}


I fill each child collection of each box with a single box and I do that up to 15 times, so that the hierarchy contains up to 15 levels.

Box -Box --Box ---Box

...... 15 times

In the handler of the loaded event of the MainPage.xaml.cs the collection is populated like so:

C#
ObservableCollection<Box> boxCollection = new ObservableCollection<Box>();

 Box lastBox = new Box();
 lastBox.BoxName = "Box Nr. 1";
 lastBox.Boxes = new ObservableCollection<Box>();

for (int i = 1; i < 15; i++)
{
 Box newBox = new Box();
 newBox.BoxName = "Box Nr. " + (i + 1);
 newBox.Boxes = new ObservableCollection<Box>();
 newBox.Boxes.Add(lastBox);
 lastBox = newBox;
}

boxCollection.Add(lastBox);
MyListBox.ItemsSource = boxCollection;


The listbox's items template is a hierarchical data template defined in the resource section of App.xaml.

XML
<sdk:HierarchicalDataTemplate x:Key="NestedDataTemplate">
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Border Grid.RowSpan="2" Background="LightGray" Opacity="0.5"/>
    <TextBlock Text="{Binding BoxName}"/>
    <ListBox Grid.Row="1" ItemsSource="{Binding Boxes}" ItemTemplate="{StaticResource NestedDataTemplate}"/>
  </Grid>
</sdk:HierarchicalDataTemplate>


When I run the app, it crashes and throws the following exception which can be investigated in the Application_UnhandledException handler in the App.xaml.cs.

The exception:

C#
Error HRESULT E_FAIL has been returned from a call to a COM component.


   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth


Note: If I reduce the amount of hierarchy layers of the box collection, everything works fine.

Please help, I have been struggling for several days. I cannot find anything in forums or blogs.

Thank you
AnswerRe: Silverlight: Exception with ListBox and nested collection Pin
Mycroft Holmes13-May-14 12:56
professionalMycroft Holmes13-May-14 12:56 
QuestionWPF Generate Dynamic Messages Including Links Pin
Kevin Marois6-May-14 16:44
professionalKevin Marois6-May-14 16:44 
AnswerRe: WPF Generate Dynamic Messages Including Links Pin
Bernhard Hiller6-May-14 20:58
Bernhard Hiller6-May-14 20:58 
QuestionCreating multilanguage WPF MVVM application Pin
sifi mohamed amine2-May-14 4:43
sifi mohamed amine2-May-14 4:43 
QuestionMultiBinding Question Pin
Kevin Marois1-May-14 14:32
professionalKevin Marois1-May-14 14:32 
QuestionUpdate Instance Property From DP Pin
Kevin Marois29-Apr-14 6:29
professionalKevin Marois29-Apr-14 6:29 
AnswerRe: Update Instance Property From DP Pin
Richard Deeming29-Apr-14 6:34
mveRichard Deeming29-Apr-14 6:34 
GeneralRe: Update Instance Property From DP Pin
Kevin Marois29-Apr-14 6:37
professionalKevin Marois29-Apr-14 6:37 
QuestionWPF Style Question Pin
Kevin Marois28-Apr-14 7:18
professionalKevin Marois28-Apr-14 7:18 
AnswerRe: WPF Style Question Pin
Pete O'Hanlon28-Apr-14 7:24
mvePete O'Hanlon28-Apr-14 7:24 
GeneralRe: WPF Style Question Pin
Kevin Marois28-Apr-14 7:27
professionalKevin Marois28-Apr-14 7:27 
GeneralRe: WPF Style Question Pin
Pete O'Hanlon28-Apr-14 8:09
mvePete O'Hanlon28-Apr-14 8:09 
AnswerRe: WPF Style Question Pin
pradeep surya10-May-14 5:37
pradeep surya10-May-14 5:37 
QuestionPass Logging Method Pin
Kevin Marois24-Apr-14 12:01
professionalKevin Marois24-Apr-14 12:01 
AnswerRe: Pass Logging Method Pin
Matt T Heffron24-Apr-14 12:49
professionalMatt T Heffron24-Apr-14 12:49 
QuestionWPF TextBlock Trigger Question Pin
Kevin Marois24-Apr-14 7:45
professionalKevin Marois24-Apr-14 7:45 
AnswerRe: WPF TextBlock Trigger Question Pin
Richard Deeming24-Apr-14 8:24
mveRichard Deeming24-Apr-14 8:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.