2011-07-05 7 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から継承したクラスがある場合、SMFPlayerの代わりにこの子クラスをxmlns:...を使用するように指定する方法はありますか? – Neykho

+0

@Neykho、はい。 SMFPlayerから継承したクラスへの名前空間パスを知る必要があります。次に、新しいxmlnsを追加するか、xlmns:smfを変更して新しいパスを使用します。 xmlns:name = "clr-namespace:TypicalThisIsNameOfYourProject.RestOfTheNamespacePath" ' – ShawnFeatherly

関連する問題