2010-07-13 5 views
2

Silverlight Toolkit을 사용하면 기본 끌어서 놓기를 매우 쉽게 할 수 있습니다.ListBoxDragDropTarget은 ListBox가 부모 컨트롤을 채우지 못하도록합니다.

http://silverlightfeeds.com/post/1325/Silverlight_Toolkit_adds_DragDrop_targets.aspx

는 불행하게도 보인다 래퍼 ListBoxDragDropTarget 나사까지 부모 컨트롤에 자신을 스트레칭하는 것입니다 목록 상자의 일반 기본 동작 - 등이 예에서 그리드 셀로.

<Grid Background="Yellow"> 

<toolKit:ListBoxDragDropTarget AllowDrop="True"> 
     <ListBox x:Name="customerListBoxMain" 
       DisplayMemberPath="Name"> 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
      <StackPanel Orientation="Vertical"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
     </ListBox> 
    </toolKit:ListBoxDragDropTarget> 

</Grid> 

나는 노란색 상자의 중간에 앉아 그 내용에 맞게 크기가 조정 작은 목록 상자와 함께합니다 (ListBox에 데이터를 바인딩 후) 여기까지.

HorizontalAlignment=Stretch 등의 금액이 없기 때문에 부모 상자를 채울 수있을 것 같습니다.

ListBoxGrid으로 채우려면 어떻게해야합니까?

답변

0

내가 지금까지 가지고있는 가장 좋은 점은 변경하려는 래퍼 그리드의 크기를 듣고 수동으로 크기를 업데이트하는 것입니다. (XAML에서이 작업을 수행 할 수 없어서 이벤트를 사용해야했습니다.)

<Grid Name="myListBoxWrapper" SizeChanged="myListBoxWrapper_SizeChanged">    
    <controlsToolkit:ListBoxDragDropTarget AllowDrop="True">     
    <ListBox x:Name="myListBox" > 

및 코드 숨김에서

:

private void myListBoxWrapper_SizeChanged(object sender, SizeChangedEventArgs e) 
    { 
     myListBox.Width = myListBoxWrapper.ActualWidth; 
     myListBox.Height = myListBoxWrapper.ActualHeight; 
    } 
+0

현재 드래그 기능이 충분히 안정적이지 않으며 어쨌든 모든 종류의 wierdness로 끝났습니다. –

6

ListBoxDragDropTarget은 콘텐츠 컨트롤에서 파생됩니다. HorizontalContentAlignment 및 VerticalContentAlignment를 설정하면됩니다. HorizontalContentAlignmentVerticalContentAlignment 설정 Archil 말했듯이

.....

+0

실제로, th 나를 위해 일한거야! ListBox에 너비/높이를 설정하지 말고 Vertical/HorizontalContentAlignment를 Stretch로 설정하십시오. –

+0

이 게시물을 우연히 만났을 때이 솔루션이 저에게 효과적이었습니다. –

0

은 갈 수있는 방법이지만, 또 다른 방법은 아마 WidthActualWidthListBoxHeightListBoxDragDropTargetActualHeight을 결합하는 것입니다 :

<toolkit:ListBoxDragDropTarget x:Name="dragdroptarget" AllowDrop="True"> 
    <ListBox x:Name="customerListBoxMain" 
     DisplayMemberPath="Name" 
      Width="{Binding ElementName=dragdroptarget, Path=ActualWidth}" 
      Height="{Binding ElementName=dragdroptarget, Path=ActualHeight}" > 
     <ListBox.ItemsPanel> 
      <ItemsPanelTemplate> 
       <StackPanel Orientation="Vertical"/> 
      </ItemsPanelTemplate> 
     </ListBox.ItemsPanel> 
    </ListBox> 
</toolkit:ListBoxDragDropTarget> 
관련 문제