2011-07-05 3 views
0

기본적으로 다음 코드 집합을 동적/프로그래밍 방식으로 만들려고 시도하고 있지만이를 수행하는 방법을 잘 모르겠습니다.격자에 버튼과 실버 라이트 플레이어를 동적으로 추가 하시겠습니까?

<Grid x:Name="LayoutRoot"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition/> 
    </Grid.RowDefinitions> 

    <smf:SMFPlayer x:Name="player" Grid.Row="0" AutoPlay="False"> 
     <smf:SMFPlayer.Playlist> 
      <media:PlaylistItem 
       DeliveryMethod="AdaptiveStreaming" 
       MediaSource="http://video3.smoothhd.com.edgesuite.net/ondemand/Big%20Buck%20Bunny%20Adaptive.ism/Manifest"/> 
      <media:PlaylistItem 
       DeliveryMethod="AdaptiveStreaming" 
       SelectedCaptionStreamName="textstream_eng" 
       MediaSource="http://streams.smooth.vertigo.com/elephantsdream/Elephants_Dream_1024-h264-st-aac.ism/manifest"/> 
     </smf:SMFPlayer.Playlist> 
    </smf:SMFPlayer> 

    <StackPanel Grid.Row="1" Orientation="Horizontal" Background="Transparent"> 
     <Button x:Name="test1" Height="30" Width="70" Content="Test 1"/> 
     <Button x:Name="test2" Height="30" Width="70" Content="Test 2"/> 
    </StackPanel> 
</Grid> 

는 여기 정적으로 보이는 방법은 다음과 같습니다 http://i.imgur.com/uz1O8.png

감사합니다!

답변

1

우선 StackPanel에 이와 같은 이름을 지정해야합니다.

<StackPanel x:Name="spBottom" Grid.Row="1" Orientation="Horizontal" Background="Transparent"> 
     <Button x:Name="test1" Height="30" Width="70" Content="Test 1"/> 
     <Button x:Name="test2" Height="30" Width="70" Content="Test 2"/> 
</StackPanel> 

그런 다음 코드 숨김에 다음 줄을 추가해야합니다.

For iLoop As Integer = 0 to 4 
    Dim btn As New Button With {.Content = "Button" & iLoop} 
    spBottom.Children.Add(btn) 
Next iLoop 

이 정보가 도움이되기를 바랍니다.

0

xmlns (XML 네임 스페이스) 접두사가없는 컨트롤은 사용하지 않고 코드 숨김에서 만들 수 있습니다. 예를 들어, C#으로 다음 코드를 사용하여 XAML에서 StackPanel의를 다시 만들 수 있습니다 :의 xmlns 접두사

StackPanel panel = new StackPanel() { Orientation = Orientation.Horizontal, Background = null }; 
panel.SetValue(Grid.RowProperty, 2); 
LayoutRoot.Children.Add(panel); 

요소, 콜론 아무것도 같은 <smf:는 코드 숨김에서 네임 스페이스의 지식을 필요로합니다. 연관된 네임 스페이스는 첫 번째 요소에 정의되어 있으며 xmlns:smf="PathToTheNamespace"과 같습니다. 이 네임 스페이스는 대개 C#의 코드 숨김 파일에서 맨 위에 using PathToTheNamespace 문을 추가하여 다시 표시됩니다.

+0

SMFPlayer에서 상속 된 클래스가있는 경우 xmlns : ...를 통해 SMFPlayer 대신이 자식 클래스를 사용하도록 지정하는 방법이 있습니까? – Neykho

+0

@Neykho, 네. SMFPlayer에서 상속 한 클래스의 네임 스페이스 경로를 알아야합니다. 그런 다음 새 xmlns를 추가하거나 xlmns : smf를 변경하여 새 경로를 사용하십시오. 즉'xmlns : name = "clr-namespace : 일반적으로 ThisIsNameOfYourProject.RestOfTheNamespacePath"' – ShawnFeatherly