I'm following this reference to implement an autocomplete textbox in my application:
http://www.broculos.net/2014/04/wpf-autocompletebox-autocomplete-text.html
I notice there is a difference when using an itemtemplate vs not using one. When using a template the items have more space between them. I need to use the itemtemplate but how can I make it look more like when not using a template, move the items closer to each other?
When not using an ItemTemplate, the single items in the dropdown list will be simple strings and will be represented by TextBlocks in the UI. TextBlocks don't have any margin by default, so the lines are close together.
Assigning an ItemTemplate will replace this visual appearance (with whatever the ItemTemplate defines). Most probably there is some margin/padding defined in the ItemTemplate, e.g. if an Label is used as representation (Labels have some default margin assigned).
Changing the margin/padding properties of the single elements of your ItemTemplate should help here.
Related
Is it possible to use the parts of default WPF controls for binding?
Specifically, I'm aiming at binding the padding size of a ListBox control to the width of the arrow part of a ComboBox control.
Using VS 2015 Live Visual Tree, I can see that the specific part I'm interested in is named 'splitBorder', which is the portion of the ComboBoxToggleButton that contains the downwards arrow symbol.
Specifically, I'm aiming at binding the padding size of a ListBox control to the width of the arrow part of a ComboBox control.
No, you can't really do this since the width of the arrow and the arrow itself is hardcoded within the ControlTemplate of a ToggleButton that is part of the default ControlTemplate of the ComboBox.
You cannot bind to the arrow Path from any element outside of the control template where it is defined and the ComboBox class doesn't expose the arrow from any public property that the ListBox can bind to. So this is not possible I am afraid.
I have a list of properties that have a value and a type, and depending on the type, various controls should be added to stackpanel. ie - for text TextBox should be used, for double - some sort of numericupdown control. Can this be implemented with MVVM? Any help is appreciated.
You can use an ItemsControl with implicitly applied DataTemplates (add them to Resources, set DataType only (use x:Type)).
ItemsControl because the StackPanel is the last step that only allows UI elements as children, ItemsControl accepts data as items.
I'm trying to use TabControl template from MSDN.
http://msdn.microsoft.com/en-us/library/ms754137.aspx
Everything works fine until TabStripPlacement comes into the game.
Setting TabStripPlacement to “Left” doesn’t work. I’m getting this result.
While I need this template works with horizontal and vertical tab placement.
I’m not so familiar with styling and templates please help me to resolve this.
EDIT:
I expect this result when TabStripPlacement is set to “Top”
And this when TabStripPlacement is set to “Left”
Just like a normal TabControl
That TabControl template you lniked is an example, not the default.
You need to expand the Grid in the template to be 2x2 instead of 1x2, then create a series of Triggers that set the Grid.Row and Grid.Column of the TabPanel named HeaderPanel, and the Border object containing the content based on the TabStripPlacement
You can look at the actual default TabControl.Template by extracting the template using Expression Blend, or using the tool like Show Me The Template. It contains the triggers you'll want.
I have a list of textual descriptions, each of which a user must score on a scale of 1-5. The number of textual descriptions is variable, so I can't just define a static Grid in XAML.
The following image shows approximately what I'm after:
In ASP.NET, I could bind my list of text items to a Repeater control. For each row, the text would be displayed in a Label, and next to it would be a DropDownList that contains a static list of items. Is there a similar control available in Silverlight?
Should I be using one of these?
DataGrid
ListBox
Custom control derived from ItemsControl
(Other)
I solved this by using an ItemsControl, and within the ItemTemplate I placed the TextBlock and ComboBox controls.
The only wrinkle for me was that the ComboBox depended on a separate DataContext, so I had to resort to using the DataContextProxy described in this article
How can i add different items with either background/foreground color different in WPF listbox?
You can can create a DataTemplete, set it to ListBox.ItemTemplate and use DataTrigger to change the display of the items.
ListBox has some very annoying behaviors that make styling it using data template difficult - in this blog post you will find the list of workarounds.
You may use an AlternationCount property, more info provided by this link
Or you can add to your objs binded to a listbox Background and Foreground properties and bind them in a DataTemplate of ListBox.ItemTemplate and change them in code however you like, properties must update themselves on every changing.
After tearing my hair out with this one (and your particular usecase might differ from mine) I found the WPF Toolkit's DataGrid cured all my needs.