c# WPF Combobox selected item text cut off - c#

Not sure where in the combobox style I can fix this. If you need me to post code let me know, but the style code is pretty long. Below is the combobox less the style.
<ComboBox x:Name="user_combobox" Margin="115,62,0,0" Height="26" Width="306"
HorizontalAlignment="Left" VerticalAlignment="Top"
IsReadOnly="True"
Foreground="White" Background="SteelBlue" BorderBrush="White" OpacityMask="RoyalBlue"
Style="{StaticResource ComboBoxFlatStyle}"
ItemContainerStyle="{StaticResource ComboBoxItemFlatStyle}"
MaxDropDownHeight="{Binding User_Combobox_Height}"
ItemsSource="{Binding Username_List}">
<ComboBox.Resources>
<SolidColorBrush x:Key="ComboBoxHighlightBrush" Color="RoyalBlue" />
</ComboBox.Resources>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=username}" Margin="0,-1,0,1" Height="22" FontSize="16" FontWeight="Bold" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

A wild guess, but is it possible that in your "ComboBoxFlatStyle" Style, you're setting a value for Template property of the ComboBox? If so, check your Margin value for any Control you've set there, you probably have some top or bottom margin that are too restrictive.

I know, this answer is pretty old, but in case anyone faces the same issue again:
I had the same exact problem. I solved it thanks to the answer of Roger Leblanc. Changing widths and heights didn't change anything. But adding a Padding of 0 (or higher) solved it.

Related

Autocomplete combobox vs2017 - properties

I have a problem with combobox. I do not have properties for him. Where can I find AutoComplete properties?
Typing also does not suggest anything to me and as I enter the whole thing, I get the error.
I'm explaining what I mean - I have a combobox with many list records.
I would like the combobox to open, for example, the first three letters.
this is my code of combobox
<ComboBox
x:Name="combolista"
HorizontalAlignment="Left"
Margin="10,384,0,0"
VerticalAlignment="Top"
Width="491"
Grid.Column="1"
SelectionChanged="ComboBox_SelectionChanged"
ItemsSource="{Binding Wyszukanie_miast}"
SelectedItem="{Binding WybraneMiasto}"
IsEditable="True"
TextSearch.TextPath="Miasto">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Miasto}" />
<TextBlock Text="Województwo" Margin="70,0,0,0"/>
<TextBlock Text="{Binding Wojewodztwo}" Margin="150,0,0,0"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
He works but I would like to enter all the possibilities in three letters
you can use telerik : RadAutoCompleteBox if you want, but telerik is not a free library.
you can also take a look at https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit

TabControl position TabItems

I have TabControl.
I want move tabs to the left but window with content should not change the size.
Result:
My code:
<controls:TabControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" x:Name="MyTabControl" BorderBrush="Transparent" BorderThickness="0" Padding="0">
<controls:TabControl.Resources>
<DataTemplate x:Key="ClosableTabItem">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="textBlockName" VerticalAlignment="Center" Text="{Binding}"/>
<HyperlinkButton Margin="6,0,0,0" x:Name="tabItemClose" VerticalAlignment="Center"
Click="tabItemClose_Click">
</HyperlinkButton>
</StackPanel>
</DataTemplate>
</controls:TabControl.Resources>
<controls:TabItem Header="Main" x:Name="MainTabItem" ToolTipService.ToolTip="Main" >
</controls:TabItem>
</controls:TabControl>
I won't really post a huge answer with a lot of XAML , rather i will give you some basic ideas of what you can do :)
1.Inside each tabitem,just add a grid and create two columns.Place every required element in the middle column and make sure the Grid's HorizontalAlignment and VerticalAlignment are set to Stretch
You can customize the template of your tabcontrol and set required width/margin of TabPenl/ContentPresenter.
I think 1 is the easiest solution so far,if you want to use 2 , leave a comment and i'll add some helpful XAML
Hope this helps :)

Preventing items in ListBox from exceeding its width

I'm sure this is simple, but I just can't seem to figure it out. Basically, I'm trying to force ListBoxItem from allowing itself to go outside of ListBox width. For example, let's say we have a crude ListBox with a TextBox for each ListBoxItem:
<ListBox HorizontalContentAlignment="Stretch">
<ListBoxItem>
<TextBox TextWrapping="Wrap"/>
</ListBoxItem>
<ListBoxItem>
<TextBox TextWrapping="Wrap"/>
</ListBoxItem>
<ListBoxItem>
<TextBox TextWrapping="Wrap"/>
</ListBoxItem>
</ListBox>
If you were to type in them, the text, eventhough it has TextWrapping set to Wrap, will continue flowing to the right, as the width of the ListBoxItem and the ListBox adjust to the width of the content (note that the HorizontalScrollBar appears):
I'm sure this is an intended behavior and is probably caused by the ScrollViewer within the template, but I want the text to wrap and be contained within the original width. I can solve this by setting a static width, but it would be a sketchy design decision and not something I want to do (it would restrict things from being re-sized easily).
Basically, the behavior I'm seeking is that of an ItemsControl:
<ItemsControl>
<TextBox TextWrapping="Wrap"/>
<TextBox TextWrapping="Wrap"/>
<TextBox TextWrapping="Wrap"/>
</ItemsControl>
I just want to keep the ListBox control because of its other behaviors, which I need. Any ideas?
This will disable the horizontal scrolling (even though it sounds like it's only disabling visibility):
<ListBox HorizontalContentAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">

Silverlight: ComboBox Behavior

really simple problem, but I guess I have just the wrong definition of combobox:
I'd like to get a simple thing like:
http://www.c-sharpcorner.com/uploadfile/mahesh/combobox-in-silverlight/
But whenever I add a combobox (or a listbox) and set the itemssource, it shows directly all items and I dont have a textbox-like selection.
My approach was quite simple:
In XAML I define:
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Style="{StaticResource styleStdWidth}" Text="Spieler 1:" />
<ListBox x:Name="lsbPlayerOne" ItemTemplate="{StaticResource dtName}" Width="300" />
<TextBox x:Name="txtPlayerOnePoints" Style="{StaticResource stylePlayerWidth}" />
</StackPanel>
<DataTemplate x:Name="dtName">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" FontSize="35" FontWeight="Bold" x:Name="txbname"/>
</StackPanel>
</DataTemplate>
And in Code behind I just set the ItemsSource with a List, which has data.
Since the ListBox gets bigger every time I add a item, it gets uglier and uglier.
Am I missing a property, which I didnt find? I did not see anything...
Sorry for the confusing question :)
P.S.: I tried the same as in the example shown in the link. Sadly I cant open the sample project.
Matthias Müller
Your question is unclear. But you are not implementing a combobox in the code you have shown. Why don't you use a combobox and set your itemsource to the list that contains the fields you want to use?
<ComboBox ItemSource={Binding Names}/>

Switch template based on parent property. Possible?

Here is my scenario. Working with Bing Map control(MVVM):
<m:Map x:Name="MainMap"
ZoomLevel="{Binding MapZoomLevel, Mode=TwoWay}"
Center="{Binding MapCenter, Mode=TwoWay}"
LogoVisibility="Collapsed"
CopyrightVisibility="Collapsed"
CredentialsProvider="{Binding BingApiKey}"
UseInertia="True"
Mode="Road" Grid.Column="2" Grid.RowSpan="5">
<m:MapItemsControl
ItemsSource="{Binding Source={StaticResource WorkLayerData}}">
<m:MapItemsControl.ItemTemplate>
<DataTemplate>
<Border m:MapLayer.Position="{Binding Location}"
Background="LightPink" BorderBrush="Black">
<TextBlock Text="{Binding DisplayId}" />
</Border>
</DataTemplate>
</m:MapItemsControl.ItemTemplate>
</m:MapItemsControl>
</m:Map>
On a bottom you see how I bind my "custom" pushpins by simply declaring DataTemplate with Border and TextBlock.
What I want is to declare 3 templates for the same item and choose them based on ZoomLevel property of MainMap
For example, when ZoomLevel<=3 I willdisplay small dots, when it is between 3 and 8 I will display more fancy pushpin with ID and when it's 8+ I may display even more info.
It's a simple idea but I'd like to know if possible..
Have a look at a DataTemplateSelector solution for Silverlight.

Categories

Resources