Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Data Template In Listbox

Data Template In Listbox

Scheduled Pinned Locked Moved WCF and WF
questiondiscussion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BlitzPackage
    wrote on last edited by
    #1

    Good people, I have two quick questions: 1) I have a data template that's rather long.   How do I get it to scroll?   Right now, it only shows the top part.   Do I have to use a scroll viewer? 2) When I select something, the text and some elements in the template disappear.   Any thoughts? Thanks for any information you can provide. Blitz

    M 2 Replies Last reply
    0
    • B BlitzPackage

      Good people, I have two quick questions: 1) I have a data template that's rather long.   How do I get it to scroll?   Right now, it only shows the top part.   Do I have to use a scroll viewer? 2) When I select something, the text and some elements in the template disappear.   Any thoughts? Thanks for any information you can provide. Blitz

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      By default, ListBox scrolls by item (logical scrolling) and what you want is physical scrolling. You can set the ListBox's ScrollViewer attached property's CanContentScroll property to false, e.g.

      <ListBox `ScrollViewer.CanContentScroll="False"` ItemsSource="{Binding Source={StaticResource MyItemCollection\_design}}" Height="100" >
          <ListBox.ItemTemplate>
              <DataTemplate DataType="{x:Type local:Item}">
                  <Border CornerRadius="8" BorderThickness="2" BorderBrush="Black" Background="LightSteelBlue" Height="150" Width="150" Margin="4"  >
                      <TextBlock Text="{Binding Name}" VerticalAlignment="Bottom" Margin="8" />
                  </Border>
              </DataTemplate>
          </ListBox.ItemTemplate>
      </ListBox>
      

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • B BlitzPackage

        Good people, I have two quick questions: 1) I have a data template that's rather long.   How do I get it to scroll?   Right now, it only shows the top part.   Do I have to use a scroll viewer? 2) When I select something, the text and some elements in the template disappear.   Any thoughts? Thanks for any information you can provide. Blitz

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Also, if you don't need ListBox functionality (selected items) but just need a scrollable panel of template-created UI elements, you can use an ItemsControl wrapped in a ScrollViewer, e.g.

        <ScrollViewer Height="100" Background="SteelBlue" >
            <ItemsControl ItemsSource="{Binding Source={StaticResource MyItemCollection\_design}}" >
                <ItemsControl.ItemTemplate>
                    <DataTemplate DataType="{x:Type local:Item}">
                        <Border BorderThickness="2" BorderBrush="Black" Background="LightSteelBlue" Height="150" Width="Auto" Margin="4" >
                            <TextBlock Text="{Binding Name}" VerticalAlignment="Bottom" Margin="8" />
                        </Border>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
        

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        B 1 Reply Last reply
        0
        • M Mark Salsbery

          Also, if you don't need ListBox functionality (selected items) but just need a scrollable panel of template-created UI elements, you can use an ItemsControl wrapped in a ScrollViewer, e.g.

          <ScrollViewer Height="100" Background="SteelBlue" >
              <ItemsControl ItemsSource="{Binding Source={StaticResource MyItemCollection\_design}}" >
                  <ItemsControl.ItemTemplate>
                      <DataTemplate DataType="{x:Type local:Item}">
                          <Border BorderThickness="2" BorderBrush="Black" Background="LightSteelBlue" Height="150" Width="Auto" Margin="4" >
                              <TextBlock Text="{Binding Name}" VerticalAlignment="Bottom" Margin="8" />
                          </Border>
                      </DataTemplate>
                  </ItemsControl.ItemTemplate>
              </ItemsControl>
          </ScrollViewer>
          

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          B Offline
          B Offline
          BlitzPackage
          wrote on last edited by
          #4

          Thanks Mark.   You answer about the scrolling was right on point. Regarding the selected item issue, I am so knee-deep in development that I have to use the list box.   Many other aspects are tied to it.   Is there a way to disable this behavior for the list box? Thanks again, Blitz

          M 1 Reply Last reply
          0
          • B BlitzPackage

            Thanks Mark.   You answer about the scrolling was right on point. Regarding the selected item issue, I am so knee-deep in development that I have to use the list box.   Many other aspects are tied to it.   Is there a way to disable this behavior for the list box? Thanks again, Blitz

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            BlitzPackage wrote:

            Is there a way to disable this behavior for the list box?

            Disable what behavior?

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            B 1 Reply Last reply
            0
            • M Mark Salsbery

              BlitzPackage wrote:

              Is there a way to disable this behavior for the list box?

              Disable what behavior?

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              B Offline
              B Offline
              BlitzPackage
              wrote on last edited by
              #6

              Actually, I figured it out. I am using data templates.   When the user selects an item in the list box, anything black within the template (e.g. text, etc...) disappears.   I noticed that there are various ways to set style triggers, etc...   However, I concluded that this was a bit much. So, my solution: in the selection change event of the list box, I just set the selected index to -1.   Since this is a read only listbox, it works out fine. Thanks again for your help. Blitz

              M 1 Reply Last reply
              0
              • B BlitzPackage

                Actually, I figured it out. I am using data templates.   When the user selects an item in the list box, anything black within the template (e.g. text, etc...) disappears.   I noticed that there are various ways to set style triggers, etc...   However, I concluded that this was a bit much. So, my solution: in the selection change event of the list box, I just set the selected index to -1.   Since this is a read only listbox, it works out fine. Thanks again for your help. Blitz

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Oh yeah - the selected item thing....I completely forgot about the second question, sorry. :)

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups