I am having an issue with binding a ComboBox to an IEnumerable<BitmapImage>, where the images are stored on the server and downloaded on demand. At the time the binding actually takes place, most of the images have not downloaded yet and causes the ComboBox to display empty selections in their place. Is there an easy way of forcing the bound images to update as their download completes. I would like to do this asynchronously; i.e., I don't want to wait until they are all downloaded before binding the list to the ComboBox.
All suggestions are welcome, including proposing alternative approaches.
I'm experiencing a similar problem. My hacked solution is to set each BitmapImage to a dummy Image control's source. As long as the Image control is visible, it works. Then I just collapse the Image after every BitmapImage was "loaded".
I´m working on a similar solution. The way i display images in a combobox and load them on demand is, that i define an Image-Control as DataTemplate and bind the the Source of the Image-Control to the URL of corresponding image file.
This way it´s up to the Image control to load the Image on Demand (when it gets displayed)
XAML:
<ComboBox Items="{Binding Images}">
<ComboBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageUrl}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
C#:
public class ImageViewModel{
public string ImageUrl {get; set;}
}
Related
I am new to XAML and C#
I have an icon created already in a project and and I have to use this icon whenever I select one of the option from the dropdown menu.
I made a stackpanel in XAML file
<StackPanel Name="stackPanelforIcon">
</StackPanel>
In the code behind file I have different cases for the dropdown menu.
case IconOnSelect:
?????? = IconList.NewIcon;
This NewIcon is the one already created and I am using the source also for this
using IconProject.Iconlists;
On writing IconList.NewIcon I am not getting any error, it is referenced correctly.
What should I write at ?????? to reference it. Is there any other way apart from using stackPanel to include an icon
A StackPanel cannot show an icon on it's own. You need a control for it, for example an Image.
<StackPanel Name="stackPanelforIcon">
<Image x:Name=theImage" />
</StackPanel>
Then you can use your Icon in your code behind like this:
this.theImage.Source = IconList.NewIcon;
You may need to convert your value, you never said what type it actually is.
Please note that using code-behind is not the preferred way with WPF. Using MVVM is way easier and more natural working with WPF, using code-behind you will fight WPF all the way. Using MVVM, this could be:
<StackPanel Name="stackPanelforIcon">
<Image Source="{Binding CurrentImage}" />
</StackPanel>
with your ViewModel having a property called CurrentImage that you would set when you want to change it. Don't forget to implement INotifyPropertyChanged for the changes to take effect though.
I have Listview with templated items (which looked just like Windows Explorer). My problem is when I openning folder which contains a whole lot of files that ListView loads those files not smoothly.(see video: http://screencast.com/t/bY7ucELj9I).
Does someone has any idea how to solve it?
You may need to virtualize your ListView's Items. Example
<ListView Name="ListViewWithVirtualization" Height="100" Margin="5"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling" />
If you set VirtualizingStackPanel.VirtualizationMode = “Recycling” then each container will get reuse instead of destroy. You will get better performance by specifying VirtualizationMode to Recycling than basic default virtualization. See http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.aspx
On my XAML page I have a text block with following binding:
<TextBlock Width="{Binding ActualWidth, ElementName=SessionList, Mode=OneWay}" ... />
This binds to a grid view:
<GridView x:Name="SessionList" ItemsSource="{Binding Sessions}"... />
Now when the page first loads and data is available, the text block will be visible and have the correct width. When the page loads and there is no data, the text box will not be visible because of the bound width.
But ... when I load up data in the background and after a while the data comes in (through MVVM) the list will be show, but the text block width will not change accordingly, and setting it as TwoWay has no effect.
Any ideas/tips?
ActualWidth is not a property that you can bind to within WinRT. Not sure if you are showing static text or bound text. If bound text and data is same as GridView has then it should go away if data is null. If static data, then use a ValueConverter to set the visibility of the TextBlock based on the data being null/empty
Binding issues like this are usually caused by properties that are not bindable, i.e. they are not dependency properties and/or do not implement INotifyPropertyChanged. Whatever. I use a Attached Dependency Property or, if that does not cover enough, a behavior. Now behavior are not included in WinRT, but that problem has already been addressed ;-)
Here's the problem: I have a data-bound list of items, basically a way for users to map a request to a response. The response is an xml-based file. I'm letting them queue these up, so I've used a combobox for responses. The responses will include the full path, so they get a bit long. I want the displayed text of the combobox to be right-justified so the user can see the file name. For my static controls, I just use ScrollToHorizontalOffset() when a file is loaded and I'm done. For this dynamic list, I'd like to do it in xaml.
The "somewhat ugly" solution would be to store all the ComboBox objects as they load... then I can call ScrollToHorizontalOffset() directly, but I'd really prefer to do it a cleaner way than that! EDIT: (Actually, this may not be reasonable. A quick look at trying to hack around this issue gets into some really awkward situations trying to map my datasource items to the controls)
I've tried HorizontalContentAlignment, that only impacts the "dropped-down" portion of the ComboBox.
I've also tried to hook other various loading events, but haven't found one that works.
Using an Item template you can decide what will be shown.
You can set tooltip. You can then also use converters to add the dots.
<ComboBox x:Name="ConfigurationComboBox" VerticalContentAlignment="Center" ToolTip="saved configuration" SelectionChanged="ConfigurationComboBox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate >
<StackPanel>
<TextBlock Text="{Binding}" ToolTip="{Binding Path}"></TextBlock>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
To measure the text, see Measuring text in WPF.
I have two forms, one is an 'editor' type form where I have the ability to select multiple images from the users pc and upload them into the local database where they are stored. This works fine, I can access them and see them populated in my listbox.
However, I also want to be able to show these images on another form, for the sake of saving time - Yes, I must use another form. I am fairly new to data binding, but I still understand it enough to have implemented it quite extensively, I just can't figure out how to databind from the image object on form 2, to the listbox on Form 1. The end idea was to create a slideshow type application (only 1 part of the application).
By Form I assume Window, so there are multiple way to do this...
MVVM - This will have a view model instance bound to window 1 that will hold the URI of the selected images and the same view model instance can be bound to the other window and it will show the images on the other.
You can refer two elements from two forms if one of the forms has been marked as the Owner of another.
E.g. if Window1 is the OwnerWindow of Window2 like so...
window2.Owner = window1;
window2.Show();
On Window1, bind the Window.Tag property with the element's selected items property...
<Window x:Class="...Window1"
...
Tag="{Binding SelectedItems, ElementName=MyListBox, Mode=OneWay}">
<ListBox x:Name="MyListBox" .... />
</Window>
Then on Window2 you could use the data binding to data context for acheiving the same via that Owner.Tag property
<Window x:Class="...Window2"
...>
<ListBox x:Name="ThumbnailListBox"
DataContext="{Binding Owner.Tag,
RelativeSource={RelativeSource
AncestorType={x:Type Window}}"
ItemsSource="{Binding}" />
</Window>
Hope this helps...
You can bind directly from the database in the second form. Since you have the images stored in the local database by now, you can easily retrieve them in the second form.