I am trying to display values of all items present in a comboBox. The items are displaying as list after running the emulator.In addition, the combobox is not clickable to select an item.
<ComboBox FontWeight="Bold" x:Name="FStyle" HorizontalAlignment="Left" Margin="192,435,0,0" VerticalAlignment="Top" Height="27" Width="154" SelectionChanged="FStyle_SelectionChanged">
<ComboBoxItem Content="Normal"/>
<ComboBoxItem Content="Italic" />
</ComboBox>
What could be the problem.
Maybe it's stupid but ...
Remove that killing margin and set Height to auto, also as a general tip for future never hardcode Height and Width, but try to position controls in containers controls.
Good luck.
Related
I try to use a CheckComboBox control from the Xceed library.
When I select an item, the control displays system.windows.controls.comboxitem:"value" instead of just value
Is there a way to display only the value of the selected item without its type?
<xctk:CheckComboBox>
<ComboBoxItem Content="SA" />
<ComboBoxItem Content="NA" />
</xctk:CheckComboBox>
In this particular case it can be solved by adding the DisplayMemberPath="Content"
<xctk:CheckComboBox DisplayMemberPath="Content">
<ComboBoxItem Content="SA"/>
<ComboBoxItem Content="NA"/>
</xctk:CheckComboBox>
But whether it is a designed feature or just a serendipitous behaviour, I am not sure.
So overall it would be better in the future to read on WPF binding, and use datasources and bindings to make the code similar to what is on the documentation page.
<xctk:CheckComboBox
DisplayMemberPath="Color"
ValueMemberPath="Level"
SelectedValue="{Binding SelectedValue}"
SelectedItems="{Binding SelectedItems}" />
I'm trying to get a fresh little reactUI WPF app up and running. However ViewModelViewHost causes me problems. It does not fill the widow but stays at its minimum required measures. (as calculated off of its children)
I have this bit of XAML in my MainWindow.xaml:
<Grid Grid.Row="1" Name="WorkArea">
<reactiveUi:ViewModelViewHost ViewModel="{Binding .}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0" DataContext="{Binding DocVm}">
<reactiveUi:ViewModelViewHost.DefaultContent>
<Label Content="no file" FontStyle="Italic" FontSize="33" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</reactiveUi:ViewModelViewHost.DefaultContent>
</reactiveUi:ViewModelViewHost>
</Grid>
So there is a grid in the MainWindow and the middle part shall be occupied by the ViewModelViewHost hence applying Horizontal and VerticalAlignment. I also tired getting rid of the second grid, but no difference. What actually happens (as seen in Snoop) is: The ViewModelViewHost complies to the stretch setting but its templated part PART_CurrentContentPresentationSite does not comply. It stays at Left + Top. What should I do, how was this intended?
Replace the template...
BTW. It also seems not to be enough just to set the ViewModel-property in order to have the view binding at the view model. You also have to set the DataContext.
You need to use the HorizontalContentAlignment and VerticalContentAlignment and set those to stretch.
In WPF, is there any way to disable the scroll behavior of the ComboBox that auto-scrolls to the top of the list whenever a user reaches the end of the list? I'd rather that the list stayed at the end and the user have to manually scroll back to the top.
Heres the XAML for the ComboBox:
<ComboBox x:Name="CellProviderCombo" HorizontalAlignment="Left" Height="65" Margin="14,405,0,0" VerticalAlignment="Top" Width=" 327" Header="Cell Provider" PlaceholderText="Choose Cell Provider" DataContext="{StaticResource GlobalVars}" ItemsSource="{Binding GlobalShopInfo.CellProviders}" DisplayMemberPath="Name" SelectedValuePath="Name" IsDoubleTapEnabled="False"/>
As I said, if you scroll past the last element in the combobox it simply starts over at the bottom and the scroll bar shoots back up to the top automatically.
Turns out that the ComboBox in WPF is not the same ComboBox used in Windows Apps Windows.UI.Xaml.
The ComboBox used in Windows Apps uses a Carousel instead of a StackPanel to display its items. One of the effects this has is making it so when you reach the end of the list, it simply loops back to the top. The solution is to manually change the ItemsPanelTemplate to a StackPanel as follows:
<ComboBox x:Name="MyComboBox"> //Add other properties in this line as well if needed
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
Hope this helps anyone who has a similar issue.
To begin I would like to apologize for my english which is far from perfect (its not my native language...).
I've a problem related to databinding in my XAML code. I've a combox which is supposed to list all graphical nodes that I drop on a custom canvas. My graphical nodes are referenced in a list graphCanvas.uinodes , and each node has a name. And that's what I want to show in my combobox.
So I tried something like this:
<ComboBox ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes/name}"
Height="23" HorizontalAlignment="Left" Name="comboBox1"
VerticalAlignment="Top" Width="71" Foreground="Black" />
But even after drawing nodes on my canvas my combox is empty...
Any clue?
Thanks.
A binding using ElementName finds the WPF element with that name. I doubt that you've subclassed Canvas and added a uinodes property to it, which is the only way that Path would find something even if the path syntax were correct, which it's not.
If you look in the Output window when you run your program, you'll see an error message that tells you why the binding isn't working. That's a start.
But even then, you won't get what you want with this approach. What you probably want looks more like:
<ComboBox ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes}"
DisplayMemberPath="name"/>
or even
<ComboBox ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes}">
<ComboBox.ItemTemplate>
<TextBlock Text="{Binding name}"/>
</ComboBox.ItemTemplate>
</ComboBox>
Your binding (specifically the Path assignment) looks wrong. Assuming uinodes is an Enumerable of some sort it looks as though you are trying to bind to the `name' property of the collection, which does not exist. Try this:
ItemsSource="{Binding ElementName=graphCanvas, Path=uinodes}" DisplayMemberPath="name"
As an aside, you can use the output window to see any binding errors.
Backgorund
I am currently writing a program that allows a user to select a manufacture from a combo box. The combo box is created in wpf using the following wpf code segment:
<ComboBox Height="23" Margin="40.422,128.423,229.908,0" Name="itemProductManufacture" ToolTip="Click to open drop down menu" VerticalAlignment="Top" Text="Select A Manufacture" SelectionChanged="itemProductManufacture_SelectionChanged" DropDownOpened="itemProductManufacture_DropDownOpened">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding ManufactureId}" Width="0"/>
<Image Name="itemManufactureImage" Source="{Binding ManufactureImage}" Height="15" Width="70" Stretch="Uniform"/>
<TextBlock Text="{Binding ManufactureName}"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
The data is provided form a database and each entry has a Image, a name and an Id (intentionally not shown)
Problem
I am trying to code the behaviour of the combo box so when it is open the image height is 50 and when it is closed it is 15 this is so the image is larger when it is first displayed and then smaller once selected so it doesn't take up too much space on the form.
I have tried editing the image propities using code but am unable to accsess it using its name or any other children of the combo box.
Thanks
Jonathan
As you are using data template you won't be able to access the directly by its name.
Try something like this -
Image image = this.itemProductManufacture.ItemTemplate.FindName("itemManufactureImage", this) as Image;
One thing I am not clear is whether you want to change image size for all the items or the selected one? If you need to access the image for a particulat item in combobox you may have to use the ItemContainerGenerator.ContainerFromItem, as explained in following posts -
WPF - ItemsControl - How do I get find my "CheckBox" item that is in the ItemTemplate?
http://www.sitechno.com/Blog/HowToUseAttachedPropertiesAsAnExtensionMechanismForACheckedListbox.aspx
look at this, To know the various ways of finding controls - How can I find WPF controls by name or type?
You can edit image properties from code using binding. Or you can use triggers in Datatemplate. When comboboxitems checked properties change, you can change height property of corresponding image
Try this:
<Image Height = "{Binding Path=IsDropDownOpen,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ComboBox}},
Converter={StaticResource myBoolToHeightConverter}}" />
An example for Converter here