Disable extra row in listview wpf - 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.:)"/>

Related

WPF ComboBox is not collapsing dropdown once it loses focus

I have a very strange situation. I have ComboBox which is loaded with some items. When I click on it, the drop-down expands showing all items.
If I now open another application such as Notepad, the dropdown will not collapse which I would expect to happen. As a result, any overlapping application, such as opened Notepad, will appear as being located in between the WPF hosting the ComboBox and the ComboBox drop-down like on screenshot below. Probably the z-order is somehow totally wrong.
I believe the reason for this behavior is the fact that the dropdown did not collapse at the first place. My ComboBox is part of a Usercontrol and its xaml is like:
<ComboBox ItemsSource="{Binding ValueSet}"
SelectedItem="{Binding SelectedNode}"
DisplayMemberPath="Name"
BorderBrush="Green"
BorderThickness="1" SelectionChanged="ComboBox_SelectionChanged">
</ComboBox>
In my opinion there is no any problem with the z-order in your xaml. The actual problem is in the ComboBox template in your application. You should find the actual style(or control template) your Combo is based on and check the Popup(usually named "PART_Popup") control inside that control template. The IsOpen property of the Popup should be bound to the ComboBox IsDropDownOpened property, like that:
`IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"`
Any way you should search the solution for your problem in incorrect control template of the Combo control. There is something that make it be opened(probably by making the IsOpen property of the inner Popup control to be always true). Let me know if it you need more suggestion.

WPF bind a control visibility to the focused property of another control

I have a combobox that displays a list of items, and I want to place a button next to it which triggers a command to see the details of the selected item. So far, so good. Now I want the button to be visible only if the combobox has focus (or is in "edit" mode, but not only when the popup is open).
I thought I could bind the visibility of the button to some focus property of the combobox, something like this:
<Button Content="Details" Visibility="{Binding ElementName=elementListComboBox,
Path=IsFocused, Converter={StaticResource Bool2VisibilityConverter}}"/>
But I found no way to know if the control I want is focused or not. I looked at the FocusManager.FocusedElement, but I don't know how to get the focused control I want inside the binding. Is there a way to achieve this in XAML?
Ok, the way to get this working as I wanted is this:
<Button Command="{Binding SomeCommand}"
Content="Details"
Focusable="False"
Visibility="{Binding ElementName=elementListComboBox,
Path=IsKeyboardFocusWithin,
Converter={StaticResource Bool2VisibilityConverter}}"/>
Two key factors here: bind the button's visibility to IsKeyboardFocusWithin property of the combobox, and set the button's Focusable property to false, else it will get collapsed when you want to click on it.
Hope this is useful.

TextBox to TextBox on the fly data binding

There are two TextBox on the WPF page. While user is typing into the first TextBox, the second TextBox must display modified text from the first TextBox. As a result both values must be binded to a view model.
Can it be done with Data Binding?
I was able to get the second TextBox display text from the first one implementing DependencyProperty on my view model. But I don't have the slightest idea how to apply transformation on the fly.
Maybe there is an easy way to achieve this?
Just use databinding with UpdateSourceTrigger set to PropertyChanged:
<TextBox x:Name='txt1' Text="{Binding MyText, UpdateSourceTrigger=PropertyChanged}" />
<TextBox x:Name='txt2' Text="{Binding MyText, UpdateSourceTrigger=PropertyChanged}" />
In this case it will update ViewModel's property on the fly instead of waiting for FocusLost.

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

WPF resizing TextBlock

I have a textblock in a grid in WPF.
I want the text to dynamically size (font) when resized. At the moment textboxes, comboboxes do this, but the the textblock stays the same. Is it possible?
Instead of trying to manually rig a TextBlock to do this, just edit the default template of a TextBox and remove the border and background, then in the style make it set the IsReadOnly flag. This way you get the textblock sizing, as well as copy-paste for free.
You can use a ViewBox for this.
eg:
<Viewbox Stretch="Uniform">
<TextBlock Text="Test" />
</Viewbox>
use expression blend for getting the default template of TextBox, then you can edit it as you required.

Resources