Replacing XAML binding based on visual state in Windows 8 - xaml

I use the VisualStateManager-Element to re-locate some XAML-elements on my page based on the current Visual State.
My problem is that I use a gridview which has to become a listview when the window is snapped (because of the small horizontal space left). I bound some other elements to the gridview's selectedItem property. My first approach was to create a listview and show/hide it based on the visual state. I would need to update the binding of my other elements as well though ( from gridView.selectedItem to listView.selectedItem) which is apparently impossible in the visualstatemanager. Another possibility would be to change the binding from code behind.
Are there other solutions (preferably in XAML)?

I think the generally accepted answer would be that you should have a piece of xaml per visual state. You collapse the one that is not currently in use. You would only make changes or create bindings manually if you were going to do something that required a dynamic number of bindings or something similar. In this case you have a fixed set of bindings to a known set of UI elements, so you would simply setup all the bindings in xaml.

Related

How do i manipulate the data templates inside listbox in uwp

I am making a chat application using XAML in UWP.The side panel is consisting of users. like this.
Everything is in Listbox in which I have this template that consists one ellipse as a circle which is like an indicator,one user image,textblocks and one toggle switch.I have to give states to the toggle switch in on the state it should change the green color of circle and make it red.
I want to give this functionality in code c# in MainPage.cs. I made the object of toggle in toggled Event Handler but I am not able to access the other elements inside the data template like ellispse,textblock.
What is the other alternative way of doing this?
NOTE: It has to be in listbox because I want to use the same template for every user.
The best way to do this would be to use data binding.
You would define a ViewModel class for the item, which would contain a bool property and would react to the toggling of the switch in the setter or have a Command which you would execute when the state event changes using behaviors.
If you really want the code as a event handler on main page, you have some options. To get the item associated with the toggle, you can use its DataContext property and cast it to the data type you are using. Alternatively, you can use Visual Tree Extesnions provided by the UWP Community Toolkit. This enables you to find the parent (probably Grid) where you store all the item controls and then manually find the user image, TextBlock, etc.

WP8 ListPicker w/ SelectedValue and SelectedValuePath?

I'm working on a Windows Phone 8 app, which is basically a port of my existing Silverlight app. On one screen in the SL version, I have 10 ComboBox controls that default to nothing selected, forcing the user to make a selection before saving the item. That works great (this is my company's bug tracking application, so I want the users to be forced to make these selections, else they'll leave in a default, which will likely be incorrect).
In WP8, the powers that be seem to want us to use their ListPicker from the WPToolkit (since there is no ComboBox there or in the default controls). However, this is more a ListBox that supports SelectedIndex but not SelectedValue and SelectedValuePath. I've been using an index property in my viewmodel(this is kind of a pain since the model loads async, but I've been working around that..), but I have to default it to an actual option, which negates the business rule of forcing a selection.
I've also tried essentially copying the source code for ListPicker and have it inherit from Selector (the base control just inherits from ItemsControl), but that won't work as the Selector constructor is internal.
It seems like what I want to do is add support for SelectedValue and SelectedValuePath. Is that possible? Or am I going about this the wrong way?

Custom Control with Multiple ContentPresenters

I am trying to implement a custom control which will show different content according to 3 different control states. I've achieved this by adding a state, and 3 different content properties to my control.
What I have now is something like that.
User sets CurrentState property to one of, "Default", "CurrentStep" or "Completed".
Control switches to a different visual state via VisualStateManager.
Controls default template sets Visibility property on 3 different ContentPresenters to display single content.
It's all working with no problem. What I am struggling to do is enabling design time support. The only thing I can do is to set ContentProperty attribute to one of the content properties, so that Blend shows this property as a child in it's control tree. However this enables only one content property to be editable in design time.
What more can I do to add design time support to my control?
I would not have created a custom control with multiple contentPresenter.
To achieve what you are trying to do, most of the time, you create a control with named parts (the default winrt control templates use this "named parts" mechanism).
When your custom control state changes, you simply show/hide one or more named parts.
This way your can provide a default control template, with all the named parts you require, and to customize the control, you override the default template, and define your own parts. The show/hide logic depending on the states will remain the same, but the target control choice is up to the guy writing the template.

How to edit Expression Blend selected control part?

I am trying to edit a specific control part within a custom TabItem Template. In this case, it's the TemplateBottomSelected control part.
I'm having an issue where I cannot seem to view or edit any control parts within the template editor except the default TemplateTopSelected. Here's a screenshot of what I'm talking about:
Even though I'm selecting the "TemplateBottomSelected" grid, the only thing I can see is the template for the TemplateTopSelected item.
How the heck do I edit the other control parts within the template using the editor?
Thanks!
that's because these templates are either collapsed or the opacity of them is set to 0. :)
you can use the eye toggle button to only show the one you want to modify at design time, set the visibility to visible, do your changes, and reset it to collapsed.
please let me know if you need more info.

how to place the imagekey to the right side of the listview

I am trying to add an imagekey to my items and it works fine except that the image
appears on the leftside of the listview in vb.net.
What I am trying to do is have it appear on the right side or in another column,
but I can't seem to do that.
can anyone help?
Thanks
Gibit
I assume you want to have an image in some other column when the listview is in Detail mode. You can't do that in the standard .NET listview control by default. I believe you would need to override a bunch of drawing-related events and possibly deal with some Win32 calls to have images show in subitems.
However, there is an open source custom listview control for .NET called ObjectListView that supports this feature. You could use that instead of the built-in one.