I have a ComboBox like this:
<ComboBox>
<ComboBoxItem>ComboBox Item #1</ComboBoxItem>
<ComboBoxItem>ComboBox Item #2</ComboBoxItem>
<ComboBoxItem>ComboBox Item #3</ComboBoxItem>
</ComboBox>
and I below that I have a grid, where the rest of the UI is. And I wanted to ask what the best way would be to display a other ui for each of the items.
Like for "Item #1" I'd like to have a radio button and a text field and for "Item #2" id like to display some data in a TextBlock, ... (Note: the ComboBox should stay at the same position to switch)
I'm not quiet sure how to implement this right with the MVVM-Model and I didn't find something useful for my problem in the internet so far.
I got it to work due to the help of HighCores comment.
I looked at this link about TabControl and transfered it to ComboBox.
So my XAML looks like this:
<ComboBox Name="RouteOptions"
ItemsSource="{Binding}"
DisplayMemberPath="DisplayName"/>
<ContentPresenter
Content="{Binding SelectedItem, ElementName=RouteOptions}"/>
And for the rest I just followed the instructions of the answer of the mentioned link.
Related
Say I have a ComboBox which has an array of doubles as the ItemsSource. In that array are the numbers "1.0" and "2.5". If I change the SelectedValue to "3.0" the ComboBox goes blank. How do I get the ComboBox to display "3.0" without having to add it to the list of possible values that would appear in the drop-down box?
I guess what I'm really asking is do I need some sort of customised combobox to display an item that is not in the drop down list?
The simplest (but not best) way to achieve your requirements (gathered from the comments because you didn't explain them properly in your question) is to add a TextBlock in front of your ComboBox:
<Grid>
<ComboBox ItemsSource="{Binding Items}" ... />
<TextBlock Text="{Binding Output} Visibility="{Binding IsOutputVisible, Converter=
{StaticResource BooleanToVisbilityConverter}}" />
</Grid>
You could then add a bool IsOutputVisible property to make it visible or hide it whenever you need to... you'd need to use a BooleanToVisbilityConverter to make this work.
I have a combobox in a wpf c# application.
What i am trying to do is the following.
I have a unselected combobox, as you look at it i can see an arrow to the right hand side and a space for text on the left. For the purpose of this question i'll refer to this text as 'Cell Text'.
When you select the button it appears with a list. I want this list to contain a number of robots my GUI/PC can connect to. When i select a robot, a message is sent to this robot trying to connect with it.
The 'Cell Text' i want to display the name of the currently connected Robot. There will be situations when a connection to a selected robot would'nt be possible, also a successful connection could take 5 seconds.
What i need to do is stop the selection automatically appearing in the 'Cell Text', is this possible?
Thanks
<ComboBox ItemsSource="{Binding MyRobotOptions}" Grid.Column="1" SelectedItem="{Binding SelectedRobot}" Margin="5"/>
For an inexperienced user (no offence), one of the easiest ways you can do this is to overlay a TextBlock over the 'Cell Text', as you call it:
<Grid>
<ComboBox ItemsSource="{Binding MyRobotOptions}" Grid.Column="1" SelectedItem="{
Binding SelectedRobot}" Margin="5" />
<TextBlock Text="{Binding YourSelectedRobotName}" Background="White"
Margin="0,0,24,0" />
</Grid>
I haven't been able to test this, so you might need to adjust the Margin property values to make it fit better, but it should hide the original text value.
A better solution I think is to use a separate indicator for connection state. For example a colored border around the Combobox that turns green when connected, red when disconnected. That way you don't have to break the paradigm of a ComboBox that everyone assumes: when you select something it immediately appears selected in the ComboBox.
I have a combo box in a wpf c# application. In the xaml i am trying to do the following.
The ItemsSource comes from one variable.
SelectedItem sets a value on another variable
But i want the text displayed to come from a new variable.
How do i stop making the selected itemssource appear as the main text?
<ComboBox x:Name="ComboPlay" FontSize="14" MinHeight="20" Margin="0,2,4,4" Grid.Row="1" Grid.Column="3" MinWidth="160"
ItemsSource="{Binding ComboBoxList}"
SelectedItem="{Binding OutputChannel.Value, Converter={StaticResource ResourceKey=ValueToStringConverter}}" Grid.ColumnSpan="1"
IsEnabled="{Binding IsDriveChoiceEnabled}"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
If you mean changing the display of the item currently selected (the portion of the control shown when the dropdown is closed), take a look at Can I use a different Template for the selected item in a WPF ComboBox than for the items in the dropdown part?
Honestly, a quick search dug up that one and many similar ones. Probably the simplest way, like the linked answer, is to figure out if your item is wrapped in a ComboBoxItem and display it differently then. Or you could re-template the ComboBox. Or you could derive from it (and re-template it) and provide a separate dependency property for the template of the selected item, if you expect to reuse it in different contexts. The sky's the limit.
I have a data entry application, with (among other things) a textbox for recording comments. These comments are specific to the data being entered, and often times are redundant (same comment given for a range of data records).
I'm planning to add a combobox with a canned selection of comments to cover the most common situations. When one is selected from the combobox, the comment textbox is populated with the canned comment.
However, I also need the ability to enter additional comments after the canned message, within the textbox. But I don't want it to be possible for the canned message to be altered. All entered comments need to come after the canned comment.
Is there a way to apply static text to a textbox which cannot be altered, but still allow text to be entered below it?
The only idea I've come up with so far is to catch TextInput events and continually overwrite the beginning of the textbox content with the canned message, but the result wouldn't exactly be pretty.
You could just place a disabled TextBox immediately above the editable TextBox and remove their bottom and top borders respectively so that they look like one big TextBox.
Perhaps overwrite a TextBox template so that it contains a Panel with the Canned Message ComboBox and a regular TextBox for user input.
Style the inner TextBox so it doesn't have the regular TextBox border, and style the ComboBox so that when it doesn't have focus it doesn't show it's border either.
When the ComboBox has focus, it will look like a ComboBox inside a TextBox, and if it doesn't have focus it will just look like one big TextBox
No, as much I aware of , you can not have something like this. But you can:
Have a label on top (side) of it with static text applied
If you have enough space, have a readonlt text box for preview of the comment, more or less like SO comment editor works.
You can try to not let to delete several count of characters from binded data ( which will be actually static text)
Hope this helps.
I would adopt a slightly different strategy.
If something has been selected in the Combobox, then concatenate the input in the selected combo-box item text and the textbox text. If not, use the textbox text.
Of course you could use the selected event of the combobox to chnage the label to reflect the change in circumstance.
I think you can bind the textBox1.Text with the combobox selected item as Oneway mode. The following is code snipet
<ComboBox Height="23" HorizontalAlignment="Left" Margin="118,48,0,0" Name="comboBox1" VerticalAlignment="Top" Width="144">
<ComboBoxItem Content="Commanet 1" />
<ComboBoxItem Content="Comment 2" />
</ComboBox>
<TextBox Height="64" HorizontalAlignment="Left" Margin="118,101,0,0" Name="textBox1" VerticalAlignment="Top" Width="144" Text="{Binding ElementName=comboBox1, Path=SelectedItem.Content, Mode=OneWay}" />
2 more options.
Override the style of the textbox to include the fixed text - pass the fixed text though some templatebinding
You can capture the PreviewKey<> events on the textbox and cancel it its modifying the "fixed" text, and if not let the event go through.
But 2 textboxes that visually look as 1 is still a better option though - easiest to implement and maintain
Im cleaning up this question and going to put in an example that makes sense to me..hopefully for you too...
so lets say i have an Items control. This control is bound to an observable collection of NBA Basketball teams (Lakers, Heat, Knicks...ect). In this observable collection of NBATeams I have a property of FavoritePlayer. I have a datatemplate that lays out how this is going to look inside the Items Control. I have a textbox which displays the team name. (this could be/should be read only..its not now) but it displays the team name.. LA Lakers. the second item in my items control is a combobox. this combo box will ultimately display my favorite player on each team.
The itemssource on the combobox is from a lookup value i have. It displays all the people on the team and the displaymemberpath on this combobox is "DisplayText"...I need my selected item on this combobox to be shown. so if my favorite player is Kobe Bryant the combo box should display this.
<telerik:RadComboBox Grid.Row="0" Grid.Column="9" Width="150" EmptyText="--Select Player--"
ItemsSource="{Binding PlayerList}"
SelectedItem="{Binding FavoritePlayer, Mode=TwoWay}"
DisplayMemberPath="DisplayText" HorizontalAlignment="Left"></telerik:RadComboBox>
I am used to just having textblocks in a listbox and then when an item is selected from within that listbox i use that selected item to bind my comboboxes that live outside of my listbox. Now i actually have the combobox in the listbox(ItemsControl now). So Im wondering the best way to bind the combobox from within an ItemsControl
I initially was just having issues getting the players to show up in the combobox..but I solved that by doing the code below.
I found my first issue of just binding the items source to the combo box from within an items control.
I had to set the bindings to look like this.
ItemsSource="{Binding DataContext.PlayerList, ElementName=ItemsControlNBATeams}"
so i had to set the name of the items control and use that in the element name and set the path = to DataContext.PlayerList. this now brings up the items in my combo box..what it doesnt do is set the selecteditem of my combo box.
Not very clear about your you are asking but does this answer your question
<ListBox ItemsSource="{Binding}" x:Name="ListBox1"></ListBox>
<TextBox Text="{Binding SelectedItem, ElementName=ListBox1}"> </TextBox>