L
Lloyd Sheen
Hey, I am attempting to move an ItemTemplate to a usercontrol. It is
currently in a listbox and I want to make the content of a listitem a
usercontrol.
I am stuck at how to bind. For the Listbox it is simple , just bind the
ItemsSource. In my mind I should be able to move the template to a
usercontrol and then replace the Listbox.ItemTemplate to use the
usercontrol.
Where I am stuck is with the binding. I currently get the info from Linq to
SQL and then bind it.
The current Listbox XAML code is as follows:
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="2"
Margin="5">
<StackPanel x:Name="sPanel"
Orientation="Vertical" Width="200" Height="100" >
<Button Click="Button_Click" Tag="{Binding
ElementName=sPanel}" Background="Transparent" >
<Image Source="{Binding
Path=DisplayURI}"
Height="48" Width="48"
/>
</Button>
<TextBlock Text="{Binding Path=DisplayName}"
/>
<Expander x:Name="ShowSongsExpander"
Header="Show Song List" Expanded="ShowSongsExpander_Expanded" Tag="{Binding
ElementName=SongList}">
<ListBox x:Name="SongList">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel
Orientation="Horizontal" >
<TextBlock
Text="{Binding Path=TrackNumber}" Margin="5"></TextBlock>
<TextBlock
Text="{Binding Path=Title}" Margin="5"></TextBlock>
<TextBlock
Text="{Binding Path=Artist}" Margin="5"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Expander>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
I have moved it to a usercontrol and now the ItemTemplate looks like:
<ListBox.ItemTemplate>
<DataTemplate>
<local:RFolderCtrl></local:RFolderCtrl>
</DataTemplate>
</ListBox.ItemTemplate>
How do I pass the binding of the object to the usercontrol.
Thanks
Lloyd Sheen
currently in a listbox and I want to make the content of a listitem a
usercontrol.
I am stuck at how to bind. For the Listbox it is simple , just bind the
ItemsSource. In my mind I should be able to move the template to a
usercontrol and then replace the Listbox.ItemTemplate to use the
usercontrol.
Where I am stuck is with the binding. I currently get the info from Linq to
SQL and then bind it.
The current Listbox XAML code is as follows:
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Red" BorderThickness="2"
Margin="5">
<StackPanel x:Name="sPanel"
Orientation="Vertical" Width="200" Height="100" >
<Button Click="Button_Click" Tag="{Binding
ElementName=sPanel}" Background="Transparent" >
<Image Source="{Binding
Path=DisplayURI}"
Height="48" Width="48"
/>
</Button>
<TextBlock Text="{Binding Path=DisplayName}"
/>
<Expander x:Name="ShowSongsExpander"
Header="Show Song List" Expanded="ShowSongsExpander_Expanded" Tag="{Binding
ElementName=SongList}">
<ListBox x:Name="SongList">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel
Orientation="Horizontal" >
<TextBlock
Text="{Binding Path=TrackNumber}" Margin="5"></TextBlock>
<TextBlock
Text="{Binding Path=Title}" Margin="5"></TextBlock>
<TextBlock
Text="{Binding Path=Artist}" Margin="5"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Expander>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
I have moved it to a usercontrol and now the ItemTemplate looks like:
<ListBox.ItemTemplate>
<DataTemplate>
<local:RFolderCtrl></local:RFolderCtrl>
</DataTemplate>
</ListBox.ItemTemplate>
How do I pass the binding of the object to the usercontrol.
Thanks
Lloyd Sheen