WPF Binding Confusion, combo box trying to change selected value before values loaded? - binding

Why isnt this selected value binding working? I am utterly confused here. When I load the page, the first text box properly shows the contents of 'SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID', in this case '20'.
What SHOULD happen is when the page is first loaded, the combobox should have the note with ID 20 preselected.
However, the combobox and the second text box are both empty (but the list of notes is populated). As soon as I selected an entry, the 2nd combobox is updated with the newly selected Note ID.
This only happens when the page is first loaded. As soon as I select a different SelectedComponentAnalysisViewModel it all works fine and the appropriate value is automatically selected in the combobox.
My only guess here is that somehow the combobox is trying to bind to the selected value before it is populated. Is there some way to force it to wait till its populated to bind? Or at least make it try to bind after it has been populated? Or maybe the reverese is happening and its trying to load before its datasource is loaded? But if that were the case, then I would expect the first text box to be empty.
(the text boxes are just there to help me debug this)
<ComboBox x:Name="ReactionEffectNoteSelector" ItemTemplate="{DynamicResource DataTemplate1}" ItemsSource="{Binding NoteViewModelList}" SelectedValuePath="NoteID" SelectedValue="{Binding SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID, Mode=OneWay}">
<ComboBox.Resources>
<DataTemplate x:Key="DataTemplate1">
<TextBlock TextWrapping="Wrap" Text="{Binding NoteID, Mode=OneWay}"/>
</DataTemplate>
</ComboBox.Resources>
</ComboBox>
<TextBlock HorizontalAlignment="Right" Text="{Binding SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID}"/>
<TextBlock HorizontalAlignment="Right" Text="{Binding SelectedValue, ElementName=ReactionEffectNoteSelector, Mode=OneWay}"/>

Why are you binding the SelectedValue to SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID and then setting SelectedValuePath to NoteID? That implies that there is a SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.NoteID.NoteID property.
I think you want to set SelectedValue set to SelectedComponentAnalysisViewModel.ReacEffectViewModel.Note.

Related

Xamarin Forms ListView selection-background paints over an item-background

For a xamarin forms project on my iPhone/iOS (12.4), I'm using ItemTemplate to showing ViewCells of a ListView.
This looks like this:
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
...
<Frame
BackgroundColor="{Binding Value, Mode=OneWay, Converter={StaticResource PositionToBackgroundColorConverter}}"
BorderColor="{Binding Value, Mode=OneWay, Converter={StaticResource PositionToTextColorConverter}, ConverterParameter={x:Static model:ItemComponent.Border}}">
...
This works pretty fine, sofar a selected item is not set. When I select an item, the selected row are drawing by the framework, and its background is set to gray. In this state the background of the frame is not drawn correctly. Or the background of the selection "overpainting" the background of the frame.
Do you know a (simple?) method to redraw the Frame, after the selected item is changed?
EDIT:
For example, to easier understanding the problem, I put here an image with two ViewCells. The first ListItem is not selected, the second ListItem is selected. This is a symbolic illustration of unwanted behavior!
When the ListItem is selected it should looks like this here:

UWP - How to apply CharacterSpacing to PlaceholderText

I want to know that is there any way to apply CharacterSpacing to PlaceholderText in TextBox?
I tried to edit TextBox template and I noticed a ContentPresenter is showing PlaceholderText, I tried to use CharacterSpacing on it, but it did not work. Also, I tried FontStretch and again no result.
I tried to edit TextBox template and I noticed a ContentPresenter is showing PlaceholderText, I tried to use CharacterSpacing on it, but it did not work
The PlaceholderText is presented inside a ContentControl for the when use default style. And PlaseholderText is the value of content property. The type of content property is object, in the meanwhile, CharaterSpacing property is an attribute for string. So it seems like this is the reason why CharaterSpacing doesn't take effects. You will find controls with Text property such as TextBox,AutoSuggestBox and TextBlock can take effects on CharaterSpacing property since the type of Text property is string.
How to apply CharacterSpacing to PlaceholderText
If you want to apply CharaterSpacing to PlaceholderText here, you can use TextBox control instead of the ContentControl for PlaceholderTextContentPresenter to be a new style which will not influence the PlaceholderText feature. But you need to do some changes for appearence to let it seems same with before. Update code for the new TextBox style as follows:
<TextBox
x:Name="PlaceholderTextContentPresenter"
Grid.Row="1"
Grid.ColumnSpan="2"
Margin="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
Foreground="Gray"
CharacterSpacing="1000"
IsHitTestVisible="False"
BorderThickness="0"
Text="{TemplateBinding PlaceholderText}" />
And the result:

ZK BindComposer value set programmatically not applied while retrieving

I am using zk BindComposer for form binding. I have a combobox to which I set value programmatically . When I retrieve the value it's null. How to refreshing programmatically set value while using bindcomposer?
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('in_raster_hms.formCtrl.patient.PatientViewModel')"form="#id('patient') #load(vm.patient) ">
<combobox id="comboCity" selectedItem="#bind(patient.city)" ></combobox>
Controller:
comboCity.setSelectedIndex(2);
I set selected item programmatically. When I retrieve patient object from binder the value of comboCity is null. I think the combobox selection to be reload.
If I choose from combo manually it works fine.

Alter text in normal TextBox with Surface-On-Screen-Keyboard

Is there a possibility to use the Surface-keyboard to alter text in a normal textbox?
I'm creating a textbox and add the text in code behind. And now I want that the user can change the text if he touches the text.
<Grid x:Name="TextContainer" Margin="0,0,0,0" Background="Transparent" Height="66" Width="66">
<TextBlock x:Name="contentTextBlock" Margin="0" Text="NodeDesign_X" VerticalAlignment="Center" d:LayoutOverrides="Width" HorizontalAlignment="Center" Foreground="White" TextTrimming="CharacterEllipsis" TextWrapping="WrapWithOverflow" />
</Grid>
I didn't find possibilities to alter the SurfaceTextBox in the way my TextBlock locks now.
Thanks in advance!
Use a TextBox instead of TextBlock then the user can change the text. If you are in Surface Mode the Keyboard will be automatic popup if the TextBox gets the focus.

How do I get all values from a listbox that are not selected in ASP.NET MVC

I have a form that (amongst other things) contains 2 multi-select listboxes. Basically you can add items to the one on the right from the full list of items on the left using some add/remove buttons.
The problem is that I cannot see a way of picking up the contents of the listbox when posting back to the controller.
I have followed this example:
http://ittecture.wordpress.com/2009/04/30/tip-of-the-day-198-asp-net-mvc-listbox-controls/
This works fine if you have actually selected the items in the listbox before posting. That's not really the way I think this UI should behave though.
Hope that makes sense,
Nick
Thanks for the help guys. I forgot to mention that I am populating the selected items listbox with jQuery. Not sure if that was important or not though.
In the end, I fixed it by selecting all items onclick with jQuery before posting. Seemed like the easiest solution.
I don't think a listbox is the control you want for the control on the right. The way a listbox works (by posting the selected item) is not what you're trying to achieve.
You could consider having a grid or even just a div with a number of strings. There is more Javascript/JQuery to be written, but it will provide a nice user experience because no postbacks will be needed until all the work is complete.
You'll need to use JavaScript/JQuery to add and remove items from the div based on the buttons to add and remove.
In addition, for each item that is added on the right, you'll need to add a hidden input field:
<input type="hidden" id="SelectedItems" value="..." />
Set the value to the key or id of the newly added item. If you remove a field from the right control, make sure you remove the associated hidden field.
To handle items on the right that the user has removed, you'll need hidden fields to indicate which have been removed:
<input type="hidden" id="RemovedItems" value="..." />
Then in your controller you can add two parameters to the Action (or add two field to the viewmodel) which will be arrays of strings. This will be set to all of the values in the hidden fields that were added, and all the ones that were removed.
In addition to listbox, have several hidden input fields to hold "currently added" items. The listbox selection will indicate "items to remove" when selected.
OK, clarification. You have left and right listboxes. Left one holds available items, and selected ones are POSTed and then added. Right one holds currently added items, and selected ones are POSTed and then removed from added items.
Now, you also need to hold currently added items. You can do this via bunch of
<input type="hidden" name="currently_added" value="itemid" />
hidden fields.
Yes you can go jQuery but this is an easy way; not every site should be designed to require JavaScript turned on. The above solution works without JavaScript enabled.
Your post from page will give you 3 arrays:
Left side box selected items to add
Right side box selected items to remove
Hidden fields - already added items
You take (3), remove (2) from it, add (1) to it, and display the same page or do whatever you want.

Resources