What I'm Trying to Achieve:
I've created a ListBox with a custom control template using Blend. I want to be able to change it's scrollbar. In blend, I've tried editing the scrollviewers style/ template, but the scrollviewer would look weird, and it wouldn't scroll the items. Also, I've created a style for a ScrollBar Control (in Blend), but I can't seem to use it with my ListBox. If there is a way I can "swap it" with the original boring one, that would be awesome. Thanks in advance. This is the what I have now (the ScrollBar in this example is the one I created, just dragged over the ListBox, so it doesn't really work):
XAML for ListBox:
<ListBox x:Name="ListBox1" Grid.Row="2" Background="#FF141414" Opacity="0.995" BorderBrush="Black" BorderThickness="1">
<ListBoxItem x:Name="LBIMouseLeftButtonDown" Background="#FFE62828" Content="MouseLeftButtonDown" Style="{DynamicResource ToolBoxItemStyle}" Selected="LBIMouseLeftButtonDown_Selected"/>
<ListBoxItem Content="MouseLeftButtonUp" Style="{DynamicResource ToolBoxItemStyle}"/>
</ListBox>
Related
I'm creating a ListBox with items that have a portion of the text highlighted. This would normally be a search term, but for this simple example I'm just using "NEW". The highlighting works (lifted from a tutorial), but when mouse is over the text portion of the ListBoxItem it does not get the blue highlight and cannot be selected. Clicking in the white space to the right of the text does allow it to be selected. How can I fix the Runs so that they accept the mouse hover and selection?
Sample VS solution utilizing WPF: https://www.dropbox.com/s/m8bhogp3k75rkoj/RunHoverTest.zip?dl=0
Left side of window is normal ListBox, right side is with highlighting applied in OnLoaded event.
I looked into adding a mouse hover event to the Run but got stuck on how to pass it down to the TextBlock. Any suggestion to do the highlighting differently to make it work is also welcome. Thanks.
Create an explicit DataTemplate in the view:
<ListBox Name="HighlightedListBox" Grid.Column="1" ItemsSource="{Binding AllStates}"
Loaded="ListBox_OnLoaded">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
This should make the items selectable.
Im about to create a diagram designer, and have create nodes and edges as usercontrols.
I have an stackpanel where I want to place them. I have managed to make it works with the following code:
<Window.Resources>
<DataTemplate DataType="{x:Type Model:Node}">
<Canvas>
<View:NodeUserControl></View:NodeUserControl>
</Canvas>
</DataTemplate>
</Window.Resources>
<StackPanel Name="DisplayArea">
<ItemsControl ItemsSource="{Binding Nodes}" >
</ItemsControl>
</StackPanel>
Where Nodes is an observablecollection
But this also shows an {NewItemPlaceholder} text and I can't figure out why. Would really appreciate if someone could point out my mistake.
EDIT: I have tried to create a new solution with just the beforementioned code and this doenst show the [NewItemPlaceholder}. Now Im really confused can't see the difference and what else that would cause this.
I got the same issue and the cause was that die source data was bound twice: One time to a DataGrid control and a second bound to an ItemsControl. The ItemsControl shows its items on a canvas and also {NewItemPlaceholder} becomes visible there.
The solution was to avoid adding new items to the DataGrid by:
ok. I didn't need adding.
I have a list (ListBox) of items in XAML using a StackPanel- based element template. The layout is fine, but I would now like to have a rectangle as a background for each item - creating a box around each one.
I was thinking of using a Canvas somehow, but as each item's height varies (as well as the height of the items inside the StackPanel), I'm not sure how to do it (I'm new to C#/XAML). What would be the best composition for the template in this situation?
You can just specify it in an ItemTemplate and it will do what you want, something like;
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Border BorderBrush="Red" BorderThickness="2" Background="Blue"/>
<!-- Insert the rest of your Item template stuff here -->
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
ListBox is a type of ItemsControl, which exposes several properties to control the appearance of the items. In this case, have a look at ItemContainerStyle (in the case of ListBox, the item containers are instances of ListBoxItem). You could, for instance, set the Background property in an ItemsContainerStyle to some color.
Sorry guys, I had asked this question earlier but could not figure out the answer. Made an edit to see if that bumps it, but that did not seem to work. So here is the last try to the question
I can't seem to figure out how one can get the value of a specific textblock in a listbox. To start things off, here is the code:
<ListBox HorizontalAlignment="Left" Name="listItems" VerticalAlignment="Top" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="210" >
<Grid Height="210" Background="#75FFF8DC">
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener Tap="GestureListener_Tap"
DoubleTap="GestureListener_DoubleTap"
Hold="GestureListener_Hold"
Flick="GestureListener_Flick"/>
</toolkit:GestureService.GestureListener>
...CODE...
</></></>...
The code area contains a bunch of other grids, partitions (columns and rows) and textblocks. Here is an example:
<Image Name="XXX" Source="{Binding XXXPath}" Stretch="Fill"
Grid.Column="0"/>
<TextBlock Name="YYY" Grid.Column="1" Grid.Row="0"
Text="{Binding YYYPath}" Foreground="Black"/>
<TextBlock Name="ZZZ" Grid.Column="2" Grid.Row="0"
Text="{Binding ZZZPath}" Foreground="Black"/>
So what I want, is if someone taps the grid (that means anything in the grid, including these textblocks and images), I want to first get the text of the textblock "YYY."
I could have inserted that code into a textblock and used sender as textblock, but I do not want to limit my gestures to one textblock, nor do I want to repeat that for each element in the grid (lots of issues and seems unnecessary).
Edit: If this does not work, I can also implement just one tap gesture (but again, for the whole grid) and use that to get the value of the textblock. Is there no way? Otherwise I will have to do this: Add tap for the textblock and use sender as a textblock, then get the value of the text. But I really do not want to use this approach.
I see you use bindings for your textblocks and image. So why don't you use ( if you haven't already done it) an IList instance of class which hold an information about them? Then set this instance as an ItemSource for your listbox. That way when user taps somewhere on listbox you can catch the SelectedIndex or SelectedItem of a listbox item. And this will help you to figure out which element of IList collection to extract so you could get your text or image or whatever you need.
And you don't need to use GestureServices from external Silverlight Toolkit with Mango. Tap, DoubleTap etc. are built-in.
Since TextBox doesn't allow smooth scrolling, I've used it as a ListBoxItem. It works great. But when I enter many lines, the cursor goes out of the view, down below the list box, because of it I'm unable to see the text which I am typing. To see the cursor, I have to manually swipe the TextBox up.
Here's the code:
<ListBox>
<ListBox.Items>
<TextBox HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Width="467"
AcceptsReturn="True"
MinHeight="300"
MaxHeight="Infinity"
/>
</ListBox.Items>
</ListBox>
Don't set the height of the TextBox and wrap a ScrollViewer around your TextBox. That has worked for me!
Did you try the srollable textblock instead of textbox..For more details
visit http://blogs.msdn.com/b/priozersk/archive/2010/09/08/creating-scrollable-textblock-for-wp7.aspx