Neptune2 [just came from Mars] [closed] - wpf

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
well , seriously guys i got sick of WPF errors and hard handling , look i got many buttons are dsigned to represent rooms and i want to bind into a tooltip to get occupier name and informations from database .
i cant find how to do it.
Thanks

Build a RoomViewModel class that exposes Description, IsAvailable, OtherInformation, and other properties and implements INotifyPropertyChanged. How you populate these properties is up to your application.
Build a RoomsViewModel class that exposes an ObservableCollection<RoomViewModel> named Rooms.
Create DataTemplates for the RoomViewModel and RoomsViewModel classes (see below).
Create an instance of the RoomsViewModel class and populate its Rooms collection.
Create a ContentPresenter and set its Content property to the instance of your RoomsViewModel class.
Typical data templates might look like this:
<DataTemplate x:Type="{local:RoomsViewModel}">
<ItemsControl ItemsSource="{Binding Rooms}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
<DataTemplate x:Type="{local:RoomViewModel}">
<Button
Margin="10"
IsEnabled="{Binding IsAvailable}"
ToolTip="{Binding OtherInformation}"
Content="{Binding Description}"/>
</DataTemplate>
Future enhancements:
Try using a UniformGrid instead of a WrapPanel.
Read Josh Smith's article Using RoutedCommands with a ViewModel in WPF and use the techniques described there to create a ReserveRoomCommand property on the RoomViewModel. Set the CommandBinding in the RoomViewModel data template to {Binding ReserveRoomCommand}. Note that once you do this, you'll remove the binding to IsEnabled, because the command binding will enable and disable the button automatically.
If you are going to need to reuse this UI, move the data templates and content presenter into a UserControl.

Related

XAML enlighten me with this binding commands [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
what are these? I am confused with the extra properties in "Binding"
{Binding Path=Customers, Source={StaticResource customerVM}, Mode=TwoWay}
{Binding Path=GetCustomersByNameCommand, Source={StaticResource customerVM}}
{Binding Path=Text, ElementName=tbName}
{Binding Path=DataContext, ElementName=LayoutRoot}
{Binding Path=TotalIncome, Mode=OneTime}
and more of those. What are those? I mean, where are they getting the Mode, Path, etc.. I don't understand.
The only thing I can understand is
{Binding ProperyName}
{StaticResource Anythinghere}
Binding in XAML can be specified in many ways.
The simplest (shortcut) is
{Binding PropertyName}
This is equivalent to
{Binding Path=PropertyName}
This is equivalent to:
<Binding Path="PropertyName" />
Binding is actually a class with various properties such as Path, Source, Mode, etc.
More details on how to bind data in WPF can be found at : http://msdn.microsoft.com/en-us/magazine/cc163299.aspx#S2

ToggleButtons in ItemsControl bound to an ObservableCollection

First of all i want to excuse my English.
What i want to achieve looks very simple but i'm a bit lost in the implementation.
Background: I have an ObservableCollection of Contacts. these contacts all have 1 or more ContactRoles. I bind the contacts to the itemssource of an ItemsControl and want a ToggleButton for every role in the contact to be displayed.
Question: My first question is how can i go from a list of contacts with roles to a lot of ToggleButtons on screen. The second question i have is If i click one ToggleButton all other buttons that have the same contact need to be checked as well. If i click another togglebutton which belong to another contact all checked buttons needs to be unchecked and the buttons belonging to the new contact needs to be checked.
What do i have now: What i have now is an itemscontrol in an itemscontrol and the internal itemscontrol it's itemtemplate is printing the ToggleButtons look an the code below:
<Button Content="Add" Width="72" Height="27" Command="{Binding Path=AddContact}" VerticalAlignment="Top"/>
<ItemsControl ItemsSource="{Binding Path=Contacts}" IsTabStop="False" Name="Parent">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding ContactRoles}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton Content="{Binding}" CommandParameter="{Binding ElementName=Parent, Path=DataContext.Item}" Template="{StaticResource toggleButtonTemplateButtonBar}"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.ViewContact}" Height="27" MinWidth="100">
</ToggleButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
This part of the code is showing.
I hope someone can help me with this.
Some other questions i have is Do i need to make a Custom Control that inherits from ItemsControl or can this be done by templates and styles?
I you need more information let me know.
Thanks, Jordy
EDIT:
I'm sorry i was not so clear with formulating my questions. to come back on you comment. The ItemsSource of the first ItemsControl hold a list with unique contacts, the ItemsSource of the second hold a list of strings (roles) that belong to this contact. I want to show an ToggleButton for each role of all contacts. But i think you've guested that from my codeexample.
This image will show what i'm trying to do.
I hope this makes thing more clear.
As Snowbear said please provide more inputs... From your questions I see ...
My first question is how can i go from a list of contacts with roles
to a lot of ToggleButtons on screen.
What do you mean by GO? Are you asking that how are Contacts or Contact.Roles tranformed into ToggleButtons? Then that is what your ItemTemplate is doing. If you are asking that you want some property or data from Contact object to be held by the toggle button then you have already used Binding in your ItemTemplate.
<ToggleButton Content="{Binding}" Tag="{Binding Roles}">
</ToggleButton>
In the above example, Tag which is one of the non-visual properties of FrameworkElements in WPF, is bound to the list of Roles from the corresponding Contact object.
The second question i have is If i click one ToggleButton all other
buttons that have the same contact need to be checked as well.
Are you saying that in your list of Contacts some Contact object is added multiple times in the list? If so that is a bad design and may cause blunders while using ItemsSource. If no, then this statement of yours all other buttons that have the **same contact** is confusing. Do you mean that you have Contacts which may repeat but they are not the same object by reference. Probably they share by some identifying value e.g. they have same Contact.Name or Contact.ID etc.
If some identifying value of contact is what is same among different contact objects then you will have to intelligently use the SelectedValue binding.
If i click another togglebutton which belong to another contact all
checked buttons needs to be unchecked and the buttons belonging to the
new contact needs to be checked.
Again this is possible once you decide what are you really trying to do i.e. are you adding same Contact object multiple time or you have different Contact objects having some value common.
Do i need to make a Custom Control that inherits from
ItemsControl or can this be done by templates and styles?
in WPF, ANYTHING can be achieved using common templates and styles. They definitely eliminate need for creating a custom control for various visually similar looking controls.
BUT if you control has a behavior or functionality that you need to perform exactly the same in multiple places and you want it sealed and to limit itself performing that specific function, then creating a custom control makes sense.
So please rephrase your question and provide clearer inputs.

MVVM Multiple Views same ViewModel in Prism

I have a question regarding multiple user controls views with the same view model type. I can't seems to find specific answers for my confusion but this is quite speculative.
I have.
<StackPanel Orientation="Vertical">
<TextBlock Text="Signature Summary" FontSize="14" FontWeight="Bold" TextAlignment="Center" Height="30"/>
<my:ParameterFileSummaryView DataContext="{Binding ParamterFile1ViewModel}"/>
<my:ParameterFileSummaryView DataContext="{Binding ParamterFile2ViewModel}"/>
<my:ParameterFileSummaryView DataContext="{Binding ParamterFile3ViewModel}"/>
<my:ParameterFileSummaryView DataContext="{Binding ParamterFile4ViewModel}"/>
<my:ParameterFileSummaryView DataContext="{Binding ParamterFile5ViewModel}"/>
</StackPanel>
the stack panel is a container inside a main view which has a dependancy property view model datacontext used for a Prism/Unity IoC architecture.
These are therefore binding the datacontect for these individual views to properties of the interface of the main view via another interface.
It all seems to work ok and the binding of the elements in the ParameterFileSummaryView bind nicely to the values set on the, say for the first one, ParamterFile1ViewModel.
Which is exactly what I want. But of cource these ViewModels are built within the ViewModel of the main window and not out of the Unity container.... It all feels a little bit hacky. Is there a cleaner way to implement what I am attempting.
Apologies if it is really a moot question... but I can't see the wood for the trees. If the question confuses I will add edits, please be patient I am not an expert :) .
Question answered by myself and sanity checked by #Jon... Sorry SO for cluttering your questions board.

WPF ListBox Show WAIT Cursor?

I have a WPF ListBox that displays images loaded from a local folder,
usually somewhere between 1- 300).
I'm using a converter in my imageTemplate to make sure and show thumbnails of the images,
and not the images in their full size. Even while doing this, it still
can take several seconds to load initially.
My question is, how do I know in my ListBox when the loading of ListBoxItems
Begins/Ends, so that I can set the Mouse Cursor to a waiting status? I'm looking
for a way to notify that user that something is happening..
Here is what my ListBox looks like in XAML:
<ListBox SelectionMode="Extended"
ItemsSource="{Binding Path=ImageFiles}"
ItemTemplate="{StaticResource imageTemplate}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.IsDeferredScrollingEnabled="False"
VirtualizingStackPanel.VirtualizationMode="Recycling"
x:Name="images">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
Thanks!
I answered a similar question, here.
If you don't want to do a pop-up, you could also do something similar by attaching a translucent rectangle (or some other filling control), with a message/animation in front of it, to the listbox or its parent control that gets closed asynchronously like the popup in the linked answer does. I did something like that for Silverlight back before the BusyIndicator was available, and it worked quite well. I set it up as a user control with a property for the control it should cover, so it was easily re-used.

Silverlight: Datagrid like grouping in ItemsControl

Is it possible to group items in a ItemsControl or Listbox in Silverlight? These controls are bound to a DomainDataSource.
Or are there any 3rd party controls that do this?
UPDATE:
This is the sort of UI I am trying to create.
You can do this by using nested ItemsControls bound to a PagedCollectionView.
Say I have a datasource - MyItems - with fields: Category, Section and Option. I can create a PagedCollectionView from an IEnumerable(of MyItems) and tell it which fields to group by.
Dim original As IEnumerable(Of MyItems) = GetMyItems()
Dim pcv = New PagedCollectionView(original)
pcv.GroupDescriptions.Add(New PropertyGroupDescription("Category"))
pcv.GroupDescriptions.Add(New PropertyGroupDescription("Section"))
Then I bind my first ItemsControl to the PagedCollectionView
hisMyItems.ItemsSource = pcv.Groups
The PCV creates a nested hierachy like:
-Name
-Items
where Name is the value in the grouped field and Items contains the rows/objects in that grouping. I guess you could also create the PCV in xaml if you prefer.
The xaml would look something like:
<controls:HeaderedItemsControl x:Name="hisMyItems" Header="{Binding Name}" ItemsSource="{Binding Items}" >
<controls:HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<controls:HeaderedItemsControl Header="{Binding Name}" ItemsSource="{Binding Items}" ItemsPanel="{StaticResource ItemsPanelTemplate1}" >
<controls:HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Option}" />
</DataTemplate>
</controls:HeaderedItemsControl.ItemTemplate>
</controls:HeaderedItemsControl>
</DataTemplate>
</controls:HeaderedItemsControl.ItemTemplate>
</controls:HeaderedItemsControl>
I hope that makes sense. I have tried to simplify things from my actual app but I could have made some mistakes in copying it over. Obviously you could use normal ItemsControls or other controls too and customize with templates etc.
The DataGrid control supports grouping.
Tim Heuer has a good blog on grouping with a datagrid.
link text
Perhaps the control you are really looking for is the Accordian Control from the Toolkit.
See sample of Accordian behaviour here.
Note that the actual appearance is as style-able as any other control. The basic function is to group categories of items that would otherwise be a straight-forward List.

Resources