I'm having an issue with ListView in XAML.
I try to achieve a ExpandableList with opening animation. For this I wanted to use a ListView and StackLayout.
In the ItemSelected event, I would like to add values to the stacklayout and then increase the Height animated. But how do I get a reference to the ViewCell?
And further, is there a way to get the calculated height of the stacklayout and use LayoutTo to this value?
It might be easier to put an IsSelected property on whatever class makes up the ItemsSource of your ListView and set its value to true in your ItemSelected handler. Then you can subclass ViewCell and respond to changes in IsSelected in that class. Then put an instance of your ViewCell subclass in your ListView's ItemTemplate.
The main advantage of this approach is better encapsulation -- instead of modifying a ViewCell from your ListView, your ViewCell will be updating itself. It also insulates you somewhat from having to know the internal workings of the ListView.
Check out chapter 19 of Charles Petzold's book (PDF) for lots of useful information about working with ListViews and ViewCells.
Related
I have a series of WrapPanels within a DockPanel. I want all but the top panel to be disabled at the beginning but all panels to be visible. As the user satisfies conditions in one panel I want to enable another panel. However, I can't figure out how I can bind the IsEnabled property of the WrapPanel (or if I need to the individual elements) to a boolean in my ViewModel. Any idea?
Update2: This works amazingingly! Adding a convention for IsEnabled to Caliburn.Micro
Update: Oops I lied. It keeps resetting all of my XAML by having an object of the same type in the ViewModel.
Just realized that I can just create an instance of what I am trying to >enable/disable in the ViewModel and from that access the IsEnabled property. Not >direct but works!
I need to load a ListView entirely and get an UIControl inside each ListItem even if the item view is not displayed on the screen.
I tried the ChildViewAdded event, but it is raised only when the ListItem is displayed on the screen.
So, I need a way to prepare my UI ListView programmatically before displaying it.
Thanks in advance for your help.
Quick answer - if you need a real View for each item in your list then you don't want to use a virtualized control like a ListView.
Instead you can use repeated custom views inside a vertical LinearLayout inside a ScrollView.
If using mvvmcross, you may find a MVXBindableLinearLayout helpful to do this - it has an ItemsSource and a Template just like the MvxBindableListView.
I've no idea whether what you are trying to do makes sense, but the above should help you do it if you want to!
Don't try using a linear layout for lists with lots of items - you'll run out of resources.
I have some problems trying to update components of surface elements. I dont know if my approach to the problem is wrong, since I'm new to the topic.
My point is represented by the following diagram
According to the option that is selected in the menu, load different user controls as only child of StackPanel but i'm habing problems for update the Listview from loaded user controls, example: when I save a new item I need to recharge the list of items in the ListView
MVVM would be a good pattern here. If you have a problem passing data between controls - why not introduce them on top of unified data layer? Consider this:
Three radio buttons in your Menu, each one's IsChecked property bound to Visibility property of your respective UserControl.
StackPanel holding all three UserControls
ListView bound to ViewModel's List<Item>
Each of your UserControls bound to ListView.SelectedItem: one of them using TextBlock for read-only, one using TextBox for editing. Third one would create new item in your List<Item>. You would have to create ItemTemplate for each or create one UserControl (since they look very much alike) and use DataTemplateSelector.
If you're not familiar with MVVM here is a good start. You can also use one of the existing frameworks like MVVM Light
You can create an event on your child
public delegate void HandleNAMEOFYOURHANDLEEVENT();
on your child class
public event HandleNAMEOFYOURHANDLEEVENT yourInstance;
to use it on your child class
if (!ReferenceEquals(yourInstance, null))
{
yourInstance();
}
and you declare it on your parent like other event.
I have an ItemsControl object and am setting the DataTemplate to hold a Grid with a couple controls in it. The controls are databoud to a collection of some object MyObj, specifically a TextBlock and a ComboBox. MyObj has its own collection inside of it for a property. If that property has only 1 object in its collection, only the TextBlock is visible. But if there is more than 1 object in the collection, the TextBlock is visible and the ComboBox becomes visible once the TextBlock is clicked on.
I have the ComboBox filled up with what it needs, I just can't figure out how to specify which ComboBox needs to become visible when the TextBlock is Clicked on.
I guess my question is, how would I even go about doing this? Or, is there a better way to think about this problem?
I'm new to databinding in Silverlight and running into a bunch of issues on my own. Any help is always appreciated. Thank in advance.
One thing that you could do is add an extra property to the data item that you binding to, something like 'IsSelectionAvailable'. Make the visibility of your combobox bound to this property (via a boolean to Visibility enum Value Converter). Finally, add a click event handler for the text box that sets the IsSelectionAvailable property to true for the object it is bound to.
Hope that helps.
I'm certain this has come up before, but I haven't been able to find the answer.
I made a basic ViewModel that contains a list of People (an array of Person) with a property called SelectedPerson, which naturally points to the currently selected Person in the list of People. I also have a ListBox and a TreeView that are databound to the ViewModel's People list.
What I'd like to do is to keep the ListBox's SelectedValue and TreeView's SelectedItem in sync with with the ViewModel's SelectedPerson. The idea is that no matter how the SelectedPerson is modified (through a control, through code, etc), all the controls should update themselves properly. I can get it to work with two ListBoxes, which is nice, but I can't get it to work with a ListBox and a TreeView because the TreeView's SelectedItem is readonly and apparently unavailable through XAML.
Where should I look to get ideas on making this work?
Also note that I'm trying to make this work in pure XAML. No code-behind as XAML files in my application can be loaded and changed dynamically.
Thanks!
You can Use Selector.IsSyncronizedWithCurrentItem.
You can bind both thye listbox and treeview to the same datasource and make sure that the IsSyncronized parameter is set to true. Then any changes to the current item in one will be reflected in the other.
More information can be found here:
link text
I asked around and the best solution I could find was here
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cc73893a-3383-4328-a002-ed8fb002a19d
It works for me but it's not the most optimal solution at this point.