ComboBox with Arrow / Symbol only - wpf

I'd like to have a combobox that is really small in width and displays only the arrow. Background is to save space beside other buttons in the layout, and not visualize the selected item. But the dropdown should not be limited in width. I didnt find any properties to hide the inner textbox. Is it possible ?

In your ContentPresenter, you could set the Visibility depending on the ActualWidth of the ComboBox:
<ContentPresenter Visibility={Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth, Converter={StaticResource ResourceKey=WidthToVisibility}}
In your Converter, you check if the value is 8 or less, then return Visibility.Collapsed, else return Visibility.Visible.

Related

Disable extra row in listview wpf

I have this ListView and at the end of the last item you can click to the right and type in a TextBox, like shown. How can I disable this?
If you want to prohibit writing in TextBox of your DataTemplate of ListView, then just set 'IsReadOnly' property of TextBox to true. Let me show an example:
<TextBox IsReadOnly="True" />
Or just use TextBlock instead of TextBox. TextBlock, by default, does not give an opportunity to write inside this control:
<TextBlock Text="I am a TextBlock. You cannot change this text.:)"/>

WPF how to make datagrid column width to detect largest item?

So I'm working with a datagrid on which I've set the width property as follows:
<DataGridTemplateColumn Header="Country"
Width="{Binding Path=ActualWidth, ElementName=grid}"
IsReadOnly="True"/>
Now the column width actually adapts to the largest item, but only if its shown. In fact the grid's width will grow larger once I've scrolled to display a larger item than the previously displayed.
How can I detect the largest item of the collection and set the grid width to always adapt to it even if it's not displayed yet ?
I guess you would have to wait until the Datagrid has been loaded and afterwards call the ScrollToEnd Method of the Datarids Scrollviewer.

How to trigger PreparingCellForEdit event from a (Edit)button click in Silver light 4

I have a Data Grid in Silverlight 4 with 3 columns along with a column which contains "Edit/Apply" button.
The row cells are initially rendered as plain text and I need them to be changed to Comboboxes in the edit mode.
Once the Edit button in any of the row is clicked. I need to change the textblock( This is my Cell Template) in one of the row to the ComboBox(This is my Cell Editing template)
The question is how do i facilitate this on clicking the Edit button of each row and not by double clicking on the row.
Thanks,
Vijay
1st way
Put the textblocks on top of the combo-boxes (comboboxes with collapsed visibility). On Edit Switch visibilities between controls (Combo - visible / TextBlock - Collapsed) and Bind the Text Property from the Textblock to the selected value from the combo.
2nd way
Put only combo-boxes with IsReadOnly Property set to True. On Edit set IsReadOnly to false and on save set it back to true.*
3rd way
Make the datagrid readonly and bind a Data Form to it. The Data Form contains edit / save / cancel buttons.
If you need an example just let me know and I'll write one as soon as possible.
Not sure if this is what you expected. If not, please just ignore it. It is possible that I missunderstood the question.
Another answer
The other answer will be to use a DelegateCommand binded on the Command property of the Edit button wich can contain a parameter (the row number). This is if you are using the MVVM pattern. And in the ViewModel you could edit the selected row.
After a bit of searching / trying i was able to toggle between display and edit mode by a button click (button placed in each row).
Below posted is the sample code , which facilitates this toggle for one of the Cells in the Grid, Which makes use of Two Boolean Properties ShowDefaultTemplate and ShowEditableTemplate , The VisibilityConverter converts the boolean values to corresponding Visibility Options (Visible or Collapsed).
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding XXX}" HorizontalAlignment="Center" VerticalAlignment="Center"
Visibility="{Binding ShowDefaultTemplate, Converter={StaticResource visibilityConverter}}" />
<ComboBox HorizontalAlignment="Left" MinHeight="24" Width="100"
ItemsSource="{Binding Source, Source={StaticResource Provider}}"
Visibility="{Binding ShowEditableTemplate , Converter={StaticResource visibilityConverter}}"
SelectedItem = "{Binding SelctedItem,Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
Thanks,
Vijay

How to get or compute actual width of ListBox without Vertical Scrollbar if visible

I wonder how to get or compute actual width of ListBox without Vertical Scrollbar if visible.
What I want to do is changing width of each items inside ListBox without being covered by Vertical Scrollbar.
Width="{Binding ActualWidth,
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}
At least, above binding tell me the actual width of ListBox, but this one does not handle width of vertical scrollbar.
Is there any good way to solve this?
Try binding to the ViewportWidth property of the containing ScrollViewer instead.
Like this:
Width="{Binding Path=ViewportWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ScrollViewer}}"
Maybe the default will help you: just don't set Width at all!
At least in my case it was totally sufficient to not set the Width property. While Mårten Wikström's answer is completely correct I found out my actual problem was I had specified (unnecessarily) Width and did this in a wrong way (the same way Aki24x has reported).
This is a simplified case of my example. The solution was to just delete line 4.
1 <ListBox.ItemTemplate>
2 <DataTemplate>
3 <Border
4 Width="..."
5 >

BitmapFrame in WPF ComboBox

I have a dialog that lets the user pick a custom icon. Loaded icons are displayed in a combobox in which the user makes the selection. Here is the XAML code for the combobox:
<ComboBox
Style="{DynamicResource IconComboBox}"
ItemTemplate="{StaticResource IconTemplate}"
ItemsSource="{Binding Icons,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding Icon}"
/>
Icons is a property that returns an array of BitmapFrame.
Icon is a property for the currently selected.
What currently doesnt work is that when I through the code behind set the Icon property (for example, when displaying which Icon the user picked the last time the dialog was shown), the Combobox selection is just blank. As if I had set the property to null before calling OnPropertyChanged.
My current theory is that WPF cannot compare BitmapFrames, so when walking through the list it fails to determine any of the icons there the "equal" and thus assumes null.
In short; what is the best way to through code behind set the currently selected item, which is a BitmapFrame, in a combobox?
You can use SelectedItem or SelectedIndex in the code behind to set the currently selected item!

Resources